Thursday, December 4, 2008
Shell Scripting #5 - Palindrome Script
Keywords: Linux, Shell Scripting, Scripts, BASH, Palindrome
Following code snippet is to find whether the given string is palindrome or not:
#!/bin/shecho -n "Enter a String : "read stringoriginal=$stringlength=${#string}reversed=""for (( i=$length ; i>0 ; i-- ))doreversed=$reversed""${string:$i-1:$i}string=${string%${string:$i-1:$i}}donestring=$original#reversed=`echo $string | rev`if test $string = $reversedthenecho "Valid Palindrome String"elseecho "Invalid Palindrome String"fi
Keywords: Linux, Shell Scripting, Scripts, BASH, Palindrome
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment