Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!ames!lll-tis!lll-winken!uunet!mcvax!ukc!etive!lfcs!simon
From: simon@lfcs.ed.ac.uk (Simon Brown)
Newsgroups: comp.unix.questions
Subject: Re: what's the use of "{ list }" in /bin/sh?
Message-ID: <500@etive.ed.ac.uk>
Date: 8 Jul 88 14:17:32 GMT
References: <23590@teknowledge-vaxc.ARPA> <3305@palo-alto.DEC.COM> <12334@mimsy.UUCP>
Sender: news@etive.ed.ac.uk
Reply-To: simon%lfcs.ed@nss.cs.ucl.ac.uk (Simon Brown)
Organization: LFCS, University of Edinburgh
Lines: 47

In article <12334@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>In article <3305@palo-alto.DEC.COM> vixie@palo-alto.DEC.COM (Paul Vixie)
>writes various examples (deleted), then:
>>Summary: {list} is useful if you go southpaw with it.  Other than
>>that it seems useless and I can't imagine why it exists.
>
>Actually, it has one more use:
>
>	while { setup; test } do ...
>
>or any other place where a compound statement is needed and only
>a single statement is allowed.  (while and until are about it!)

it's not actually required for this:

	while setup; test; do ...

has the same effect (though it looks a tad more bizarre). There are no
places where only a single statement is accepted, since there is always
some special keyword (such as "do") to enable the end of a complex statement to
be recognized.

In principle, one could imagine another use for {...}:

	{ cmd1; cmd2; } > file
    or
	cmd0 | { cmd1; cmd2; }

where cmd1 and/or cmd2 effect things in the current shell (ie, they contain
variable assignments or some such). Unfortunately, all versions of sh I've
seen treat the {...} construct the same as (...) in these cases (bogusly),
so

	{ grep mumble; status=$?; grumble; } > file

and

	ps | { read firstline; cat; }

don't do what you'd expect.

Fixed in SysVr4? BSD4.4? Minix1.4? :-)


| Simon Brown                                    | UUCP: mcvax!ukc!lfcs!simon
| Laboratory for Foundations of Computer Science | ARPA: simon%lfcs.ed
| Department of Computer Science                 |            @nss.cs.ucl.uk
| University of Edinburgh, Scotland, UK.         | JANET: simon@uk.ac.ed.lfcs