Bourne shell "if" syntax
Jan Henrik Sylvester
me at janh.de
Tue Jun 11 09:57:00 UTC 2013
On 06/10/2013 21:10, dteske at freebsd.org wrote:
> Character sentinels are not required.
>
> FreeBSD's sh(1) knows (because "[" is a built-in) that when you quote a
> parameter, that it is not (even if the value begins with "-") not an operator.
What you are saying here is at least misleading. I just started up sh on
9.1 RELEASE and tried:
$ A=-z
$ if [ "$A" "" ] ; then echo z ; fi
z
$ if [ "$A" "1" ] ; then echo z ; fi
$ if /bin/[ "$A" "" ] ; then echo z ; fi
z
$ if /bin/[ "$A" "1" ] ; then echo z ; fi
$
Although "-z" is quoted, it is seen as an operator. It does not seem to
have anything to do with whether the build-in or external "[" is used.
Cheers,
Jan Henrik
More information about the freebsd-questions
mailing list