Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83 based; site homxb.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!homxb!wcs From: wcs@homxb.UUCP (Bill Stewart HO 4K-437 x0705) Newsgroups: net.unix Subject: Re: Why do people use: if [ "x$FOO" = "x" ] .... ? Message-ID: <582@homxb.UUCP> Date: Thu, 18-Apr-85 19:32:04 EST Article-I.D.: homxb.582 Posted: Thu Apr 18 19:32:04 1985 Date-Received: Fri, 19-Apr-85 01:37:03 EST References: <361@ho95b.UUCP> Organization: AT&T Bell Labs, Holmdel NJ Lines: 27 Last week I posted an article asking why people use constructs like the above instead of if [ -z "$FOO" ] or if [ "Known" = "$FOO" ] Yeah, I should have worried about the case where $FOO has a value special to test, such as "-z" or "=". The most interesting reply pointed out that the answers were different on 4.2BSD. For both ksh and SysV /bin/sh, the = operator has higher precedence than -z or -n. For 4.2 BSD it doesn't. if [ -z = -z ] ; then echo true ; else echo false ; fi On SysV and ksh, this prints "true"; on 4.2BSD it prints "false". On the other hand, if [ -z = ] ; then echo true ; else echo false; fi On 4.2BSD this prints "false"; on ksh and SysV it prints "sh: test: argument expected" So, those leftover-from-v6 constructs with the "x$FOO" are still useful. Bill Stewart, ho95c!wcs -- "The {first,last} major program written in ADA will be a COBOL interpreter." Stewart, 1984 Bill Stewart AT&T Bell Labs, Holmdel NJ HO 4K-435 x0705 (201-949-0705) ho95b!wcs ucbvax!ihnp4!ho95b!wcs decvax1harpo!ho95b!wcs