Hi there,
We often use commands grouping in shell. And in most cases we use parentheses to run commands in a subshell:
$ foo=bar
$ echo $foo
bar
$ (foo=superbar; echo $foo)
superbar
$ echo $foo
bar
But, did you know that you can run command in current shell? To do that, you should use curly braces:
$ { foo=superbar; echo $foo; }
superbar
$ echo $foo
superbar
Be careful with the tricky syntax
- Set mandatory space after the opening and before the closing curly brace
- Put a semicolon after the last command of the group or use newlines to separate commands
Happy grouping
!