Bash Script-Print the arguments in Reverse order

bash$ ./reverse a b c d
d
c
b
a
bash$


x=$*                #To set all the arguments in a variable 'x'
c=$#            #To set the total number of arguments in variable 'c'

while [ 1 -le $c ]
do
c=`expr $c - 1`     #To decrement the variable 'c' by 1
shift $c        #To shift the total arguments by count 'c'
echo $1           
set $x            #To reset the arguments by the previous arguments
done

This entry was posted by Unknown. Bookmark the permalink.

2 thoughts on “Bash Script-Print the arguments in Reverse order”

Leave a Reply