Grouping commands in the Bourne Shell (sh)

Parentheses are used to run commands in a subshell:

$ foo=bar
$ echo $foo
$ (foo=superbar; echo $foo)
$ echo $foo

Curly braces are for grouping commands into a list to run in the current shell. But 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
$ { foo=superbar; echo $foo; }
$ echo $foo

Bourne Shell command groupping


About mezzantrop

12+ years of experience in large SAN and storage environments: mainly Hitachi, HP and Brocade. Now I am a proud SAN/storage IBMer. Redbooks author. The BeaST – storage-system concept inventor. Empty – expect-like tool developer. FreeBSD enthusiast.
This entry was posted in Tips & tricks and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.