what's the use of "{ list }" in /bin/sh?
Leo de Wit
leo at philmds.UUCP
Fri Jul 8 01:57:54 AEST 1988
In article <6954 at sigi.Colorado.EDU> wu at spot.Colorado.EDU (WU SHI-KUEI) writes:
|In article <23590 at teknowledge-vaxc.ARPA> mkhaw at teknowledge-vaxc.ARPA (Mike Khaw) writes:
|>"man sh" (on ultrix) says:
|>
|> { list }
|> The list is simply executed
|>
|>Under what circumstances is this useful (i.e., why whould one want to
|>put braces around a list of commands)?
|
|[ -r "$filename" ] || { echo "Cannot open $filename for reading" ; exit 1 }
This will not work as it stands. The trouble is that '}' cannot be used as
a command separator/terminator (in this respect it is different from ')' which
indeed terminates a list - if that's the correct term). Try it in your shell:
it will prompt you with the secondary prompt for the rest of the command (I
had to learn the hard way too 8-).
So after the 'exit 1' there should be a newline or a ; (I prefer the latter),
giving:
[ -r "$filename" ] || { echo "Cannot open $filename for reading" ; exit 1; }
|is another way of writing
|
|if [ -r "$filename"
|then
| echo "Cannot open $filename for reading"
| exit 1
|fi
|
|The braces are required so that both commands are executed as if one.
Indeed. The difference in using {} and () lays in the fact that for ()
a subshell is started, while {} merely groups the commands.
|Carl Brandauer
|ihnp4!stcvax!nbires!bdaemon!carl
Leo.
More information about the Comp.unix.questions
mailing list