Say I have a myfile in the current working directory. I want to set a variable if the command runs normally, but also use its result.
$ ls myfile && v=3 myfile $ echo "$v" 3
But now I also want to pass the result, so I use the syntax { list; } { list; } for grouping commands:
$ unset v
$ {ls myfile && v = 3; } | grep myf
myfile
$ echo "$ v"
# v is not set
Bash help guide → 3.2.4.3 Grouping teams say:
{ list; }
Placing a list of commands between curly braces results in a list of commands executed in the current shell context. No subshell is created. A semicolon (or new line) requires the following list.
So, as far as I understand, v should be set to 3. But this does not happen. Why?
bash
fedorqui
source share