Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jun 1996 14:09:22 +0200
From:      Wolfram Schneider <wosch@cs.tu-berlin.de>
To:        "Jin Guojun[ITG]" <jin@george.lbl.gov>
Cc:        bugs@freebsd.org, problem@bsdi.com
Subject:   test(1) (was sh bug)
Message-ID:  <199606041209.OAA00439@campa.panke.de>
In-Reply-To: <199606031939.MAA26616@george.lbl.gov>
References:  <199606031939.MAA26616@george.lbl.gov>

next in thread | previous in thread | raw e-mail | index | archive | help
Jin Guojun[ITG writes:
>The sh in BSD does not take "-" as the argument in if statement if the
>statement has more than one comparsions.
>The following line are generating errors:
>
>if [ "$1 = "-h" -o "$1" = "-help" ]; then
         ^
you forgot a quote, but this is not the problem



>ERROR:
>+ [ -h = -h -o -h = -help ]
>[: syntax error: Undefined error: 0
>
>
>but, it works in a single argument if statement:
>
>if [ "$1 = "-h" ];	then
> ...
>fi
>
>Would some one please fix it?

workaround:
if [ X"$1" = X"-h" -o "$1" = "-help" ]; then
     ^       ^

or use a case statement:
case "$1" in
	-h|-help) echo usage;; 
esac


Note: this is a test(1) bug, not a bug in sh(1). test (alias `[') is
*not* a sh builtin.

Wolfram




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199606041209.OAA00439>