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

Re: /bin/sh != /bin/bash ? [was Re: zsh vs bash]



Craig Sanders <cas@taz.net.au> writes:

> /bin/sh and /bin/bash are not equivalent. bash is a superset of sh
> functionality. bash behaves differently depending on whether it is
> invoked as sh or as bash (at least the new version 2 does).
> 
> bash when invoked as /bin/sh is more posix compliant. when invoked as
> /bin/bash, all the bash enhancements are available.

But why would you want posix compliance, and bash extended features in
the same time? If you really need bash enhancements in init.d and other
misc scripts, invoke them with #!/bin/bash. On the other hand, if you
want to make this scripts more portable (as they should be), then
invoke them with /bin/sh, and do not use bash extended
functionality. You can always try to run it with /bin/sh as zsh to
check portability.

> e.g. /usr/sbin/dwww-doc-index from the dwww package doesn't work at all
> if the first line is '#! /bin/sh', but works correctly if the first line
> is '#! /bin/bash'.

And that's correct IMO. If you start your script with /bin/sh than use
it as posix compliant sh, if you want _any_ of other shells specific
features, start your script with explicit call to that shell, and
that'll make your script shell dependent, what it really is.

-- 
Tomislav Vujec                                   tvujec@srce.hr
---------------------------------------------------------------
To understand recursion, one must first understand recursion...


Reply to: