Path: utzoo!attcan!uunet!mcvax!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.questions Subject: Re: what's the use of "{ list }" in /bin/sh? Message-ID: <555@philmds.UUCP> Date: 7 Jul 88 15:57:54 GMT References: <23590@teknowledge-vaxc.ARPA> <6954@sigi.Colorado.EDU> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 40 In article <6954@sigi.Colorado.EDU> wu@spot.Colorado.EDU (WU SHI-KUEI) writes: |In article <23590@teknowledge-vaxc.ARPA> mkhaw@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.