Help with bash scripting.

kyiosus

Registered
Hello,

How can I get my script to echo a string that is input right after the script name (when executing the script)? (Ex: '$ ./myscript hello!' echos 'hello!').

Right now I only know how to do:
read string
echo $string

But the user has to hit enter after executing the script '$ ./myscript' and then input the string. Thanks for your help.
 
In that case each word will be make into an argument. You can access them with $1, $2, etc. So if the user typed

./myscript hi mom

$1 -> "hi"
$2 -> "mom"

Just as an aside $0 is "./myscript" and you can use this to have a script do different things depending on the name it is called.
 
Back
Top