[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Simple shell scripting question from a newbie.

On Wed, Feb 04, 2004 at 10:44:24PM +1000, Andrew Pollock wrote:

||  On Wed, Feb 04, 2004 at 05:28:27PM +1100, Lex Hider wrote:

||  > while [ x"$1" != x ]; do
||  > 	...
||  > done
||  >
||  > the same as using the -z flag for test.

... not considering the negation in there.

I would write [ "${1:+x}" ], or rather even [ "${1+x}" ], distinguishing
empty and undefined.

||  > It just looks like a weird way of doing things that occur frequently.

||  Don't take this as gospel, but I've seen it around a lot too, particularly
||  in older-school shell scripts. I'm guessing it was done before the -z test
||  existed or something...

Or more likely, many people know = and !=, and know enough to implement
the test they need.
Vincent Zweije <zweije@xs4all.nl>    | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/>      | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] |            -- Paul Tomblin on a.s.r.

Attachment: signature.asc
Description: Digital signature

Reply to: