Perch Eagle Perch Eagle - 1 year ago 66
Bash Question

How assign rev command to a variable in shell

I wanted to direct the output of rev command to a variable, I tried different methods and didn't work.

read -p "Enter the number: " n
echo $n | rev
echo "new n is: $p"

I want to assign the output of line 2 to p. How?

Thank you,

Answer Source


p=$(echo $n | rev)


p=`echo $n | rev`

For further reference, you can check this link