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

Re: #!/bin/bash

On Sun, Apr 01, 2001 at 06:20:13PM +0100, Gavin Hamill wrote:
> echo -ne "Restarting apache web server: "
> <some stuff>
> echo "done"
> And get this output:
> Restarting apache web server: done
> instead of this
> Restarting apache web server:
> done

yes but a much more portable way to do this is to use printf:

printf "Restarting apache web server: "
<some stuff>
echo "done"

echo is notoriously inconsistent across *nix platforms.  and the SUS
(single unix specification) has or at least did mandate that echo
should interpret no command line switches, when potato was unstable
ash was altered to follow that, but had to be reverted since the
startup process started looking like this:

-ne Restarting apache web server: 

but ash asside you can't depend on echo doing anything but echoing
plain text with a trailing newline, thats all it does consistently.
anything special use printf instead.  

> And anyway, why would you want to insist on 'ash' ?

its smaller, faster and just does posix.  i can think of no reason why
ANY initscript requires a bashism, you can do some really complicated
things in pure posix that work perfectly in ash.  

initscripts should be plain posix shell scripts with no bashisms, and
should have #!/bin/sh as the interpreter, this way you can link
/bin/sh to ash without any problems.  (this is perfectly allowable,
and i think is even a config question on woody's ash)  

if the script DOES have a bashism then it should have #!/bin/bash so a
non-bash /bin/sh does not break it.  but using #!/bin/bash for no good
reason is just lame.  

> sh doesn't always provide the features scripts need, but bash does, and
> thus it's the default for most scripts, because we can guarantee it will
> be present without needing a Depends: ash line for each .deb.

if the script needs to do anything non-posix, ie a bashism then it
should use #!/bin/bash as the interpreter, never assume /bin/sh ==
/bin/bash.  as far as initscripts i would like to see an example where
a bashism is required for the script to work.  (where the bashism
could not be replaced with proper posix)

Ethan Benson

Attachment: pgpOXeUBKM4Lc.pgp
Description: PGP signature

Reply to: