add array in the code please Question: Write bash script which only accepts a palindrome value in an array also print the length of the given value by the user and find the largest length palindrome word from the given values in an array Expected Output: Input a palindrome value: cat Wrong input Input a palindrome value: MOM Correct it’s a palindrome the length of the given value is 3… echo "Input a palindrome value:" read str for i in $(seq 0 ${#str}) ; do revstr=${str:$i:1}$revstr #finding reverse of the str done if [ "$str" = "$revstr" ]; then #checking if reverse of str is equal to str echo "Correct it’s a palindrome the length of the given value is ${#str}" else echo "Wrong input" fi
add array in the code please
Question: Write bash script which only accepts a palindrome value in an array also print the length of the given value by the user and find the largest length palindrome word from the given values in an array
Expected Output:
Input a palindrome value: cat
Wrong input
Input a palindrome value: MOM
Correct it’s a palindrome the length of the given value is 3…
echo "Input a palindrome value:"
read str
for i in $(seq 0 ${#str}) ; do
revstr=${str:$i:1}$revstr #finding reverse of the str
done
if [ "$str" = "$revstr" ]; then #checking if reverse of str is equal to str
echo "Correct it’s a palindrome the length of the given value is ${#str}"
else
echo "Wrong input"
fi
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images