Perch Eagle Perch Eagle - 4 months ago 11
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

Try:

p=$(echo $n | rev)

or

p=`echo $n | rev`

For further reference, you can check this link