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!

extracting all parameters 1

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
hi,

I need to obtain all the variables sent to a shell script.. I am currently doing the fwg but it doesnt seem to be working very well..

tArgs=$#
tArgs=`expr $tArgs + 1`
i=7
while [ $i -lt $tArgs ]
do
echo $i
eval echo \$$i
i=`expr $i + 1`
done

can anyone pl provide a better soln ?

thnx
 
One way:
for i; do echo "'$i'"; done
Another way (in ksh-like shell):
typeset i=1
while [ $i -le $# ]; do
echo "\$$i = '$(eval echo \$$i)'"
((i+=1))
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
A small problem here..

The first cmd (for i; do echo "'$i'"; done) works and prints all the parameters but I need the parameters starting the 7th parameter onwards (dont want the parameters 1 - 7).

The 2nd soln using while works similar to the one I posted but both have a small problem..

The last parameter is being printed as junk.. Whats strange is that the first 9 parameters are always printed fine but 10th onwards are printed junk values such as ($10 = 'C0') why is that ??

A FOR loop such as for (( i=7; i<$#; i++ )) doesnt seem to work in my shell.

thnx
 
And this ?
typeset i=7
while [ $i -le $# ]; do
echo "\$${i} = '$(eval echo \${${i}})'"
((i+=1))
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
works great now.. thnx..
although I would appreciate if you can just explain the need for $(eval echo \${${i}}) .

thnx again
 
In your shell man page have a look at Parameter substitution.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Why so complicated? If you just want to print from the seventh parameter onward...
Code:
shift 7
echo $@ | tr ' ' '\n'
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top