Results 1 to 3 of 3
Hi All,
I am pretty new to the shell scripting. Today I am stuck with the usage of positional variables. I want a shell script which takes input from command ...
- 12-22-2008 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 3
Positional variable $#
Hi All,
I am pretty new to the shell scripting. Today I am stuck with the usage of positional variables. I want a shell script which takes input from command prompt, but from the third positional variable onwards what ever i enter should be taken as a single string. for eg: I am entering username password emaild id and then some numbers 234 456 789 ie
#username password emaild id 234 456 789
what ever i entered as numbers should be taken as strings. for this i wrote a script and itz not working fine. Kindly help me to sort this out....

dep="$(4)"
num=$#;
i=5;
while($i -le $num)
do
dep=dep$i;
i=$($i+1);
done
hope my logic is correct. but the output is weird.
- 12-22-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
There are various ways to do this. First of all, you could require the arguments to be entered properly, e.g.
instead ofCode:myscript "234 456 789"
If that is not acceptable, you can assign the positional parameters to your variables, then shift the parameters and assign the rest to another variable, i.e.Code:myscript 234 456 789
Code:var1="$1" var2="$2" shift 2 rest="$@"
- 12-22-2008 #3Just Joined!
- Join Date
- Dec 2008
- Posts
- 3
Thank you and itz working fine now...


Reply With Quote