From owner-freebsd-questions Wed Jan 13 02:40:20 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id CAA08110 for freebsd-questions-outgoing; Wed, 13 Jan 1999 02:40:20 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from alice.gba.oz.au (gba-254.tmx.com.au [203.9.155.254]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id CAA08059 for ; Wed, 13 Jan 1999 02:40:14 -0800 (PST) (envelope-from gjb@acm.org) Received: (qmail 29308 invoked by uid 1001); 13 Jan 1999 10:36:21 -0000 Message-ID: <19990113103621.29307.qmail@alice.gba.oz.au> X-Posted-By: GBA-Post 1.03 20-Sep-1998 X-PGP-Fingerprint: 5A91 6942 8CEA 9DAB B95B C249 1CE1 493B 2B5A CE30 Date: Wed, 13 Jan 1999 20:36:20 +1000 From: Greg Black To: cjclark@home.com Cc: freebsd-questions@FreeBSD.ORG (FreeBSD Questions) Subject: Re: Documentation of '[]' References: <199901130625.BAA04054@cc942873-a.ewndsr1.nj.home.com> In-reply-to: <199901130625.BAA04054@cc942873-a.ewndsr1.nj.home.com> of Wed, 13 Jan 1999 01:25:05 EST Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > I am by no means a sh expert and just am interested in playing it safe > in when I can use '[].' Is this documented in the manpages somewhere? If you are writing scripts that might one day be used on very old and long obsolete Unix variants (meaning more than ten years old), you might prefer to use "test" rather than "[" -- but if you only use relatively modern systems, then you can always use "[". In the old days, the man page for sh(1) and other Bourne style shells included a warning about this. I don't know (or care) if they still do. I have only used "test" in teaching situations since the early 1980s -- "[" has been fine in the real world. It's to some degree a matter of taste. Take the following snippet of code: if test -e some_file then some_program else echo "file missing!" exit 1 fi Now compare with this: [ -e some_file ] && some_program || { echo oops ; exit 1 } Some people think the first version is a model of clarity. Others, including me, consider the second to be better because you can take in the whole concept with a quick scan of a single line. YMMV. -- Greg Black To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message