Mar 31 2007

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-​​intensive script exe­cu­tion. For POSIX-​​compliant scripts, this isn’t a prob­lem at all. How­ever, there are many third-​​party scripts which call /​bin/​sh but use shell-​​specific (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 other 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

3 Responses

  1. Steve Kowalik Says:

    I’d prefer people file bugs against either the Ubuntu or Debian pack­ages when they encounter prob­lems like this. By all means hack the script to point to /​bin/​bash in the mean­time, but please file a bug so someone can fix the script to not con­tain bashisms, or exec /​bin/​bash.

  2. Stoffe Says:

    Tire­some it may be, but it’s also the only way for­ward. If all these scripts aren’t fixed, upstream, then the next per­son will also have prob­lems with it. And the next, and the next. And not only on Debian and Ubuntu, but on any sys­tem that may ship with another default. Don’t give up, file bugs!

  3. Stu Hood Says:

    I think I remem­ber read­ing that switch­ing to Dash sped up the aver­age start up time by 34 seconds, so I wouldn’t advoc­ate chan­ging the default unless you run into the shell mis­match prob­lem a sig­ni­fic­ant num­ber of times.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

What’s wrong with my script? / 'Til All Are One by Sridhar Dhanapalan is licensed under a Creative Commons Attribution-ShareAlike Australia CC BY-SA AU licence.