Paul L. Snyder on 21 Apr 2010 06:49:13 -0700

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

Re: [PLUG] Shell scripting?

On Wed, 21 Apr 2010, Randall A Sindlinger wrote:

> I realize this is the Philly *Linux* Users Group, but it still kind of
> bothers me when I see #!/bin/sh
> Granted, on linux #!/bin/sh is symlinked to bash, but if you try to 
> use the script on some unix variant, you're in for a very big
> surprise.  /bin/sh and /bin/bash are *not* the same there.
> So, it's just me, but I always prefer explicitly saying #!/bin/bash
> on scripts I write.
> I just felt compelled to point out the (somewhat historical at
> this point) difference, 'cause it doesn't matter until it does :-)

Invoking bash as sh (that is, via the link) changes its behavior.
(It's the equivalent of invoking with the --posix option.)  It doesn't 
result in a perfect emulation of the historical Bourne shell behavior,
but it shifts a few things around so it's a bit closer.

sh is not always a link to bash.  In current versions of Ubuntu,
at least, it links to dash.  Some embedded Linux distros use ash
or busybox.

Portable shell scripting consists mostly of corner cases, and if you
think your script is portable, it still probably has nasty surprises
lurking.  If you're using bash-specific features, you should
definitely specify bash in the shebang line.

I use zsh for personal-use shell scripts, as the limitations of the
classic Bourne shell are unpleasantly confining.

Philadelphia Linux Users Group         --
Announcements -
General Discussion  --