Write a shell script to accept a string and reverse it without using rev() function, apply proper validation

echo "enter the string"

read str

len=`echo $str | wc -c`

len=`expr $len - 1`

rev=""

while test $len -gt 0

do

rev1=`echo $str | cut -c$len`

rev=$rev$rev1

len=`expr $len - 1`

done

echo $rev





Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post