[TUHS] Use of "{}" in the Shell?

Peter Pentchev via TUHS tuhs at tuhs.org
Tue Aug 4 09:09:22 AEST 2026


On Tue, Aug 04, 2026 at 08:24:57AM +1000, Dave Horsfall via TUHS wrote:
> A long time ago, in a Unix manpage far away, I saw a reference to "{}"
> which acted similar to "()" except that it did not fork e.g. "{exit}" would
> do just that :-)
> 
> Does anyone know the provenance of this Shell?  I can't seem to reproduce
> it on the MacBook or the FreeBSD box here (my Penguin box is currently
> dead).

It should work on pretty much any Bourne-compatible shell, I think.
However, there is one crucial point: you *must* place a semicolon between
the last command and the closing brace, and if you write commands on
the same line, you also *must* place a semicolon between the closing
brace and the next command :)

    [roam at straylight ~]$ dash -c 'echo first; { echo second; echo third; }; echo fourth;'
    first
    second
    third
    fourth
    [roam at straylight ~]$

However, as usual, semicolons may be replaced with newline characters:

    [roam at straylight ~]$ dash -c $'echo first; { echo second; echo third\n}\necho fourth;'
    first
    second
    third
    fourth
    [roam at straylight ~]$

It should be described under a section named something like "grouping" or
"compound commands" in your shell's manual page.

G'luck,
Peter

-- 
Peter Pentchev  roam at ringlet.net roam at debian.org peter at morpheusly.com
PGP key:        https://www.ringlet.net/roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://www.tuhs.org/pipermail/tuhs/attachments/20260804/f2142e84/attachment.sig>


More information about the TUHS mailing list