0

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,

Fazlin
  • 2,285
  • 17
  • 29
R1S8K
  • 365
  • 1
  • 3
  • 18

1 Answers1

2

To store the output of a command in a variable use a $(...) command substitution:

p=$(echo $n | rev)

For further reference, you can check this link

Community
  • 1
  • 1
Fazlin
  • 2,285
  • 17
  • 29