Having the ability to get an input command from the input console is a very great tool to have in shell scripting,
So how do we go about doing it?
Here’s the sample that i have created for your reference:
Hint: to use “$#” & $1, $2 …
1. Create the shell script:
#!/bin/sh
n_input=”$#”;
counter=0;
echo “The number of input you give is $n_input”;
while [ "$counter" -le "$n_input" ]
#Note the above must have a space after the [ and before the ].
# -le means less than or equal to
do
echo “$counter”;
$counter++;
done
#We need to denote the done in when using while loop.
2. Next is how we call our script and put in the parameters:
bash# sh myscript.sh arg1 arg2 arg3
Note: In Shell Scripting, we use this hash symbol # , to denote a comment of the entire line. However if the hash symbol is followed by a ! symbol, it means that we are saying to the system that this line is not a comment but rather a special command, which in this case declaration to the system that we are using a shell scrpt. Same applies for the symbol $ followed by # ($#) , it denotes the no of input arguments to the shell script.
-That’s All !
Hope this is usefull for all of you.
Author: Angsari Toni