what's the use of "{ list }" in /bin/sh?
Simon Brown
simon at lfcs.ed.ac.uk
Sat Jul 9 00:17:32 AEST 1988
In article <12334 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>In article <3305 at palo-alto.DEC.COM> vixie at 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 at uk.ac.ed.lfcs
More information about the Comp.unix.questions
mailing list