Are you receiv­ing syn­tax errors when run­ning a shell script on Ubuntu 6.10 (Edgy Eft)? If so, you might want to check what shell you are using. While test­ing scripts for the LCA A/​V Team a few months ago, I dis­covered that the Ubuntu developers decided to sym­link /​bin/​sh to dash, for faster and less memory-intens­ive script exe­cu­tion. For POSIX-com­pli­ant scripts, this isn’t a prob­lem at all. How­ever, there are many third-party scripts which call /​bin/​sh but use shell-spe­cif­ic (typ­ic­ally bash) syn­tax. They can be fixed by alter­ing their first line to call the most appro­pri­ate shell, for example:

#!/usr/bin/env bash

env makes it pos­sible to call bash, wherever it may lie. While my Ubuntu and Gentoo sys­tems have a /​bin/​bash, there are oth­er dis­tri­bu­tions which have /​usr/​bin/​bash or /usr/local/bin.bash.

While you can and should fix your own scripts to oper­ate in this way, con­stantly mend­ing oth­ers’ mis­takes can become tire­some. You can return your /​bin/​sh to point to bash with the fol­low­ing command:

$ sudo dpkg-reconfigure dash

When asked if you wish to install dash as /​bin/​sh, tell it to go to hell emoticon

Note that bash does use more memory, but on a mod­ern desktop machine the dif­fer­ence is neg­li­gible. This change will not affect the default login shell, since that is already bash.

 

LotD:  Obese Aus­sies get big ambulances

%d bloggers like this: