-1

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

Dreamer
  • 112
  • 1
  • 14

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
  • 497,756
  • 71
  • 530
  • 681