Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo -n "Enter a String: "
- read str
- n=${#str} #n denotes number of characters in the string
- for(( i=$n-1; i>=0; i-- )) #loop for reversing str
- do
- rev_str+=${str:$i:1} #substring of length 1 from str(char no. i) added to rev_str
- done
- echo "Is "$str" and "$rev_str" the same?"
- #echo "The String in reverse is "$rev_str
- if [ "$str" == "$rev_str" ]; then
- echo "YES. So, it's a Palindrome."
- else echo "NO. So, it's not a Palindrome."
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement