7

I was doing something very simple like: v=5 echo "$v" and expected it to print 5. However, it does not. The value that was just set is not available for the next command.

I recently learnt that "In most shells, each command of a pipeline is executed in a separate SubShell". However, in this case both commands are being executed in the same subshell.

Why does this happen? Is there any way to have this working?

Full example:

$ v=1
$ v=5 echo "$v"
1                   # I expected 5!
Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598

0 Answers0