[TUHS] Use of "{}" in the Shell?
Peter Pentchev via TUHS
tuhs at tuhs.org
Tue Aug 4 18:21:24 AEST 2026
On Tue, Aug 04, 2026 at 12:47:44AM -0600, Arnold Robbins via TUHS wrote:
> Warner Losh via TUHS <tuhs at tuhs.org> wrote:
>
> > I've not examined the source to Thompson shell closely to know if it
> > secretly does this (and that's why Steve Bourne implemented it), or if
> > that's something Bourne invented.
>
> Braces are also allowed where "do" and "done" are.
>
> I have always suspected, but never bothered to verify, that this is
> the case so that shell scripts could look more like C if one wanted
> them to. For example, in Bash:
>
> $ for ((i = 1; i <= 3; i++))
> > {
> > echo $i
> > }
> 1
> 2
> 3
Well, that's several kinds of Bash-specific syntax right there :)
(nothing wrong with that, just pointing it out)
I think that in the original implementation the main point was indeed to
be able to put more than one command in a || or && pipeline as in
my ... || { ...; exit 1; } example, or to redirect their input or
output: { printf header; command; printf footer; } | processing-command
(similar to the dash manual page example).
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/959c4e45/attachment.sig>
More information about the TUHS
mailing list