Why /bin/sh doesn't like the line: if test "x$my_var" == "xyes"; then

Dan Nelson dnelson at allantgroup.com
Thu Sep 3 05:14:02 UTC 2009


In the last episode (Sep 03), jerry M said:
> configure file got this line and it causes the message: test: xyes:
> unexpected operator But removing spaces around == or replacing == with =
> makes it to work.
> 
> On Linux though this line works fine.
> 
> Why spaces around == would cause failure?  What is the version of /bin/sh
> currently used in 7.2?  Where is it taken from?  --version, -v, -version
> don't ever print version I guess due to FreeBSD policy of not versioning
> individual utilities.

== isn't a valid comparison operator for the test command.  See the FreeBSD
manpage, or the Posix docs:
http://www.opengroup.org/onlinepubs/9699919799/toc.htm.  You need to use =.

Certain Linux distributions use bash as /bin/sh, which shortcuts the test
command internally and allows bash extensions, even in bourne-shell mode. 
Debian and Ubuntu use dash instead of bash, and this script would fail on
them as well.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-questions mailing list