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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -