Perch Eagle Perch Eagle - 5 months ago 18
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,



p=$(echo $n | rev)


p=`echo $n | rev`

For further reference, you can check this link