Path: utzoo!utgpu!watserv1!watmath!uunet!jarthur!usc!apple!vsi1!teraida!ditka!kls From: kls@ditka.UUCP (Karl Swartz) Newsgroups: unix-pc.general Subject: Re: YAkshBug Keywords: ksh bug Message-ID: <20156@ditka.UUCP> Date: 3 Feb 90 09:53:20 GMT References: <682@uncle.UUCP> Reply-To: kls@ditka.UUCP (Karl Swartz) Organization: Inaction Central, San Jose, California Lines: 42 In article <682@uncle.UUCP> jbm@uncle.UUCP (John B. Milton) writes: >Well, bug or inconsistancy: > >if [ -f * ]; then echo yes; fi > >will print "yes" if there are one or more files when using /bin/sh, but >not with ksh. Ksh gives a syntax error. Bug ... in sh (not ksh). And perhaps an inconsistancy, in that ksh does not continue the erroneous behavior. In fact, your statement isn't quite true, as ksh behaves the same as sh if there are zero or one files. It does not give a syntax error for either of these cases. And in fact, with suitable choices of filenames, ksh will not give a syntax error for more than one file: kls@ditka $ ls -0 -a -f 1 kls@ditka $ if [ -f * ]; then echo yes; fi yes kls@ditka $ Ksh simply expands the * as it's supposed to and substitutes what it finds. Since you weren't careful about what you wrote, you most often ended up feeding test what it saw as garbage; it then justly registered its indignation. Why sh doesn't behave the same way is at present an unresolved puzzle. Assuming you wish to echo "yes" if and only if there are files in the directory (ignoring dot files if you aren't root), the following will do what you want: if [ -n "`ls`" ]; then echo yes; fi -- Karl Swartz |UUCP uunet!apple!zygot!ditka!kls 1-408/223-1308 |INet zygot!ditka!kls@apple.com "I never let my schooling get in |BIX kswartz the way of my education."(Twain) |Snail 1738 Deer Creek Ct., San Jose CA 95148