Reputation: 316
I'm trying to tell a shell script information this way (when I execute it via SSH):
bash myscript.sh 'input1' 'input2' 'input3'
However I've no idea on how to convert the inputs 1, 2 and 3 into variables in shell script,
like $var1
, $var2
and $var3
.
Anybody know how?
Upvotes: 0
Views: 137
Reputation: 19528
Its very simple, the arguments passed are held in their respective numbers:
input1 would be on $1
input2 would be on $2
input3 would be on $3
And if I recall it correctly $0
is the script path/filename
And you can for example do this:
#!/bin/sh
echo "arg1='$1' - arg2='$2' - arg3='$3'"
var1="$1"
var2="$2"
var3="$3"
echo "var1='$var1' - var2='$var2' - var3='$var3'"
Not really needed but just to illustrate.
Upvotes: 3