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

Paul Vixie vixie at palo-alto.DEC.COM
Wed Jul 6 18:47:27 AEST 1988


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)?

	[ -f /etc/ptmp ] && {
		echo "hmmm, a ptmp.  maybe vipw was active at time of crash?"
	}

vs

	if [ -f /etc/ptmp ]; then
		echo "..."
	fi

I leave it to each of you out there to decide which looks better.

Or:

	[ -f /dev/console ] || {
		echo "hey, /dev/console's gone again."
		/etc/mknod /dev/console ...
	}

vs

	if [ ! -f /dev/console ]; then
		echo "..."
		/etc/mknod ...
	fi

This is a different comparison, and can be better or worse than the
first one depending on how you felt about the first one.

Summary: {list} is useful if you go southpaw with it.  Other than
that it seems useless and I can't imagine why it exists.
-- 
Paul Vixie
Digital Equipment Corporation	Work:  vixie at dec.com	Play:  paul at vixie.UUCP
Western Research Laboratory	 uunet!decwrl!vixie	   uunet!vixie!paul
Palo Alto, California, USA	  +1 415 853 6600	   +1 415 864 7013



More information about the Comp.unix.questions mailing list