Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a parameter as a variable. 1

Status
Not open for further replies.

bhagabati

Programmer
Apr 8, 2003
8
AU
I am trying to a different number of parameter to a script and check them but I don't know where did I go wrong?.

I wrote the following script

test.sh
#!/bin/sh
count=$#
i=1
while [ $i -le $count ]; do
echo "parameter " $i " is " ${i}
i=`expr $i + 1`
done

to be able to pass the parameter ./test.sh man fan ban pan tan to give the output
man
fan
ban
and so on
but I am getting
1
2
3
4
5

Can anybody help me.
 
Hi,
write instead
A=${i} so 'easy' phrase
A=$(eval echo \$$i) - it is what you need

Regards Boris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top