linux - checking if a string is a palindrome -



linux - checking if a string is a palindrome -

i trying check if string palindrome in bash. here came with:

#!/bin/bash read -p "enter string: " string if [[ $string|rev == $string ]]; echo "palindrome" fi

now, echo $string|rev gives reversed string. logic utilize in status if. did not work out well.

so, how can store "returned value" rev variable? or utilize straight in condition?

another variation without echo , unnecessary quoting within [[ ... ]]:

#!/bin/bash read -p "enter string: " string if [[ $(rev <<< $string) == "$string" ]]; echo palindrome fi

linux bash scripting

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -