what's the use of "{ list }" in /bin/sh?

Leo de Wit leo at philmds.UUCP
Fri Jul 8 14:22:25 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!)

Actually, the while keyword is followed by a command-list (according to
'An Introduction to the UNIX Shell' by S.R.Bourne, Appendix A - Grammar).

So you CAN write:

	while setup; test; do ...

And, as I pointed out in an other posting, the '}' cannot be used as a
command separator/terminator (while ')' can). So there should be a ; or
newline after test.

Another use of {} could be redirection:
     { echo This is file_a with header; cat file_a; } > file_a_hdr

Of course this can be done with () too; I don't know whether this
involves an extra sh being forked (I mean a sh more than with {}) in
this special case.

Note {} has another quirk: the '{' has to followed by white space or it
will be interpreted as part of the following word (and sh says:
syntax error:`}' unexpected).

And some American reader could perhaps tell me what Paul Vixie meant by
'to go southpaw' (probably American slang?) - although I realize that
this will keep my mailbox quite filled the next few weeks 8-).

       Leo.



More information about the Comp.unix.questions mailing list