Palindrome
Write a Shell Script to check wheather a string is palindrome or not Shell Script: clear echo enter a string read str echo Input string= $str l=`echo $str|wc -c` echo length of Input string= $l for ((i=1;i<=$l-1;i++)) do c=`echo $str|cut -c $i` rev=$c$rev done echo Reversed string= $rev if [ "$rev" = "$str" ] then echo palindrome else echo not palindrome fi OUTPUT: 1)[admin@localhost ~]$ sh strpalin.sh enter a string nayan Input string= nayan length of Input string= 6 Reversed string= nayan palindrome 2)[admin@localhost ~]$ sh strpalin.sh enter a string rakesh Input string= rakesh length of Input string= 6 Reversed string= hsekar not palindrome
Tags:
Shell Script
0 comments