JP Vossen on 18 Aug 2008 21:17:17 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] bash vs. dash


At the PLUG West meeting, Toby noted that Amazon EC2 is basically Red 
Hat-ish and expects /bin/sh == /bin/bash, thus when /bin/sh != /bin/bash 
as in the case of Ubuntu 6.06+ or Debian Lenny, Stuff Breaks.

Briefly, Bourne (sh) != bash != dash, though all are similar.  Kinda. 
If you squint a lot.

A 19 slide, reasonably stand-alone ODP version of my co-author Carl's 
"bash vs. dash" presentation is available in the zip of our Ubuntu Live 
2007 presentation: 
http://conferences.oreillynet.com/presentations/ubuntu2007/ul_albingvossen.zip
	
See also:
	https://wiki.ubuntu.com/DashAsBinSh
	http://release.debian.org/lenny/goals.txt
	http://en.wikipedia.org/wiki/Bourne_shell

The Ubuntu 'devscripts' package contains 'checkbashisms'.  From the man 
page:
	"checkbashisms, based on one of the checks from the lintian system, 
performs basic checks on /bin/sh shell scripts for the possible 
presence of bashisms. It takes the names of the shell scripts on the 
command line, and outputs warnings if possible bashisms are detected."


If you are writing for Linux only, and use stuff you know needs bash (or 
even if you are not sure), it's a good idea to use '#!/bin/bash -'.  If 
you need to run on non-Linux, '#!/usr/bin/env bash' will work as long as 
bash is installed and in the $PATH.

I talk about these issues a bit in chapter 15 of _bash Cookbook_.  Shell 
script portability is problematic for a number of reasons, and Linux 
actually makes it a bit worse.  The problem is that Linux is very 
accommodating, and even if you know what you're doing and are careful, 
you'll still probably write stuff that works fine on Linux but will 
break on a less "friendly" system like BSD, Solaris, AIX or HP-UX.  This 
isn't just a "bash" think, but is also related to all the GNU and other 
more friendly tools packaged into Linux distros.

When possible, my advice is to develop on the oldest, crappiest system 
you know you need to run on, then work up from there.  It'll probably 
Just Work on Linux and other systems may need tweaks.  Failing that, 
fire up a BSD VM and develop there.

Later,
JP
----------------------------|:::======|-------------------------------
JP Vossen, CISSP            |:::======|        jp{at}jpsdomain{dot}org
My Account, My Opinions     |=========|      http://www.jpsdomain.org/
----------------------------|=========|-------------------------------
"Microsoft Tax" = the additional hardware & yearly fees for the add-on
software required to protect Windows from its own poorly designed and
implemented self, while the overhead incidentally flattens Moore's Law.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug