Advertisement
Shailrshah

Palindrome Check

Nov 2nd, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.46 KB | None | 0 0
  1. #!/bin/bash
  2. echo -n "Enter a String: "
  3. read str
  4. n=${#str}               #n denotes number of characters in the string
  5.  
  6. for(( i=$n-1; i>=0; i-- ))      #loop for reversing str
  7. do
  8.     rev_str+=${str:$i:1}        #substring of length 1 from str(char no. i) added to rev_str
  9. done
  10.  
  11. echo "Is "$str" and "$rev_str" the same?"
  12. #echo "The String in reverse is "$rev_str
  13.  
  14. if [ "$str" == "$rev_str" ]; then
  15.     echo "YES. So, it's a Palindrome."
  16. else echo "NO. So, it's not a Palindrome."
  17. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement