’Til All Are One

Freedom is the right of all sentient beings

This blog has moved!
Please go here for the current location.

31 March, 2007

What’s wrong with my script?

Are you receiving syntax errors when running a shell script on Ubuntu 6.10 (Edgy Eft)? If so, you might want to check what shell you are using. While testing scripts for the LCA A/V Team a few months ago, I discovered that the Ubuntu developers decided to symlink /bin/sh to dash, for faster and less memory-intensive script execution. For POSIX-compliant scripts, this isn’t a problem at all. However, there are many third-party scripts which call /bin/sh but use shell-specific (typically bash) syntax. They can be fixed by altering their first line to call the most appropriate shell, for example:

#!/usr/bin/env bash

env makes it possible to call bash, wherever it may lie. While my Ubuntu and Gentoo systems have a /bin/bash, there are other distributions which have /usr/bin/bash or /usr/local/bin.bash.

While you can and should fix your own scripts to operate in this way, constantly mending others’ mistakes can become tiresome. You can return your /bin/sh to point to bash with the following 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 modern desktop machine the difference is negligible. This change will not affect the default login shell, since that is already bash.

 

LotD:  Obese Aussies get big ambulances

Powered by GNU/Linux, Apache and WordPress