Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ames!ucbcad!ucbvax!hplabs!pyramid!prls!mips!dce From: dce@mips.UUCP (David Elliott) Newsgroups: comp.unix.wizards Subject: Re: Re: /bin/test and stat(2) Message-ID: <743@quacky.UUCP> Date: Sat, 3-Oct-87 12:02:57 EDT Article-I.D.: quacky.743 Posted: Sat Oct 3 12:02:57 1987 Date-Received: Thu, 8-Oct-87 06:28:28 EDT References: <9479@brl-adm.ARPA> <29056@sun.uucp> <467@ambush.UUCP> Reply-To: dce@quacky.UUCP (David Elliott) Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 42 In article <467@ambush.UUCP> kimcm@ambush.UUCP (Kim Chr. Madsen) writes: >In article <29056@sun.uucp> guy%gorodish@Sun.COM (Guy Harris) writes: >>Don't rely on *this* behavior either - check that a string isn't null before >>handing it to "/bin/test"! > >Just how ? Write a specialized c-program "isnull"....er! >Otherwise you'll have to use test to test whether it should be passed to >test.... (-; > >Well it's two different uses of test...So I'm just picky I think... You can use the -a (boolean "and" operator) or -o ("or"). That is test " $name" != " " -a -d "$name" will tell you if "$name" is a directory, whether it is empty or not. Also, test " $name" = " " -o ! -d "$name" will tell you if "$name" is not a directory. In both cases, you use a single invokation of the "test" command, so even old shells without builtin test can work (and if you're worried about the extra fork/exec's, there's even a way to use "case" and shell globbing to find out if a file or directory exists with a single fork). (Note: I use the construct " $name" = " " because I'm very picky. This is similar to the more common $name = "" x$name = x used by many programmers. The former breaks if "$name" is "-d" or something, and the latter breaks if "$name" contains whitespace.) -- David Elliott {decvax,ucbvax,ihnp4}!decwrl!mips!dce