Monday, April 27, 2009

Some mistakes in shell programming

I've been seeing too many mistakes recently related to shell programming, due to some implemented features in GNU Bash (that are really cool if it were the only available shell on the planet). Let me tell you that it's really bad, because if those are used in some critical code to detect some implemented features, they can lead to serious problems in the build stage of the application, as I've seen with GNU autoconf generated configure scripts.

I'm posting this because I've spent a while detecting why libusb didn't have a symbol required by a dependent application; surprisingly that was due to the first mistake I'm explaining below in a configure script.

One of the most famous that you are probably aware of is the == operator used in conditionals. Remember that GNU Bash is the only shell that accepts the following:

if [ "$foo" == "$blah" ]; then
...
fi

and another one that I've just seen coming from the xorg detection block in GNU configure scripts (didn't see it until now):

BLAH="goo foo boob"
BLAH+="baobab anotherone"

This is a great mistake! those two examples (surely there will be many more) are relaying in GNU Bash for correct operation! think about it, relaying in such specific features won't do any good for all us.

No comments: