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
Post a Comment