-1

What's the difference bewteen ( ) and { } when coding in Bash ? When should I use one or the other ?

Dreamer
  • 120
  • 1
  • 11

1 Answers1

4

Braces do not start a subshell; parentheses do.

$ x=3
$ { x=4; }; echo "$x"
4
$ ( x=5 ); echo "$x"
4

Usually, unless you specifically need to localize a parameter assignment, you can use {}.

chepner
  • 446,329
  • 63
  • 468
  • 610