1

I am trying to assign the value of a string to the reversed value of another string (via the 'rev' command). I know the rev command is used like this:

$ echo "hello" | rev
olleh

But what I am trying to do is something like this:

var="hello"
rav=${$var | rev}

I know this isn't correct syntax and it doesn't work, but I was wondering if there was a way to assign a variable using a command, and if so how is it done?

Ronan Boiteau
  • 8,910
  • 6
  • 33
  • 52
Matt
  • 23
  • 3

2 Answers2

1

Try this, using command substitution:

var="hello"
rav=$(echo "$var" | rev)
echo $rav
Ronan Boiteau
  • 8,910
  • 6
  • 33
  • 52
0

Following may also help you on same.

var="hello"
rav=$(rev <<< "$var")

Output will be as follows:

echo $rav
olleh
RavinderSingh13
  • 117,272
  • 11
  • 49
  • 86