Saturday, 16 December 2017

shell script to accept a string as command line argument and reverse the same

Write a shell script to accept a string as command line argument and reverse the same.



Program:

str=$1
b=`echo $str|wc -c`
l=`expr $b - 1`
echo Lenght of String is $l
a=" "
for (( i=l ; i>0 ; i-- ))
do
c=`echo $str|cut -c $i`
a=$a$c
done
echo $a

OUTPUT:



No comments:

Post a Comment