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

 


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

Code:
str=$1
b=`echo $str|wc -c`
l=`expr $b - 1`
echo Length 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:


Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page