PDA

View Full Version : shell program not execiting?



abhilashm86
May 17th, 2009, 03:51 AM
i just tried to print command arguements in reverse order, but only last arguement i printing, also it is giving some error,


#!/bin/sh
i=$#
while [ $i -gt 0 ]
do
eval echo \$$i
i=`expr $i-1`
done

error is


abhilash@abhilash:~$ sh pgm1.sh a b c
c
[: 1: Illegal number: 3-1

what is actually missing?
in php /$$i is not shown, here it is

#!/bin/sh
i=$#
while [ $i -gt 0 ]
do
eval echo \$$i
i=`expr $i-1`
done
~

kaibob
May 17th, 2009, 04:08 AM
Try this:


eval echo \$$i
i=`expr $i - 1`

or better yet


eval echo \$$i
i=$(($i-1))

abhilashm86
May 17th, 2009, 04:12 AM
Try this:


i=`expr $i - 1`

or better yet


i=$(($i-1))

yes it worked, thanks.....
after learning C++ n object oriented, shell is little hard to crack:)