Are you receiv­ing syn­tax errors when run­ning a shell script on Ubun­tu 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­cov­ered that the Ubun­tu devel­op­ers decid­ed to sym­link /bin/sh to dash, for faster and less mem­o­ry-inten­sive script exe­cu­tion. For POSIX-com­pli­ant scripts, this isn’t a prob­lem at all. How­ev­er, there are many third-par­ty scripts which call /bin/sh but use shell-spe­cif­ic (typ­i­cal­ly 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­si­ble to call bash, wher­ev­er it may lie. While my Ubun­tu and Gen­too sys­tems have a /bin/bash, there are oth­er dis­tri­b­u­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­stant­ly 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 mem­o­ry, but on a mod­ern desk­top machine the dif­fer­ence is neg­li­gi­ble. This change will not affect the default login shell, since that is already bash.


LotD:  Obese Aussies get big ambulances

What’s wrong with my script? / Sridhar Dhanapalan by is licensed under a Creative Commons Attribution-ShareAlike CC BY-SA 4.0 licence.