install.sh portability

2 views
Skip to first unread message

sixforty

unread,
Dec 5, 2009, 4:08:09 AM12/5/09
to RETRO 10
I'm running NetBSD 5.0.1 i386. Install.sh fails unless invoked by specifying bash, ksh, or csh to run it. Running with sh fails.

Historically, "[" is a synonym, usually a link, to "test". In most shells, it's also a built-in; but if it's not for the shell one is using, [ `command` == "output" ] will fail. Outside of "[]", two equals signs are used to distinguish identity from one equal sign, which is assignment. Inside "[]", either the shell's test built-in recognizes "==" as meaning "=", or there's no built-in.

Used this way, "==" almost always works, and "=" ALWAYS works. One equal sign is more portable.

For illustration under linux (and most any shell), try:

if /usr/bin/[ 'uname' == "Linux" ] ; then echo "it is" ; else echo "it\`s not" ; fi

(/usr/bin/[ is another name for /usr/bin/test, but it requires a closing "]".

Then try it without "/usr/bin" to see the shell's built-in at work.

--
sixforty <s...@sixforty.net>
Reply all
Reply to author
Forward
0 new messages