LWN.net Logo

checkbashisms

checkbashisms

Posted Dec 19, 2010 0:18 UTC (Sun) by foom (subscriber, #14868)
In reply to: checkbashisms by epa
Parent article: Introducing the "Debian's Automated Code Analysis" (DACA) project

Because if you meant bash, you can just say "/bin/bash"?


(Log in to post comments)

checkbashisms

Posted Dec 19, 2010 0:48 UTC (Sun) by dlang (✭ supporter ✭, #313) [Link]

so why not just go through every init script and sed #/bin/sh#/bin/bash# and not have to worry about it any longer?

checkbashisms

Posted Dec 19, 2010 1:08 UTC (Sun) by foom (subscriber, #14868) [Link]

Yup. That sounds like a good plan to me :) (that's what I did with all my shell scripts when Ubuntu first started making a fuss about this.)

checkbashisms

Posted Dec 19, 2010 13:22 UTC (Sun) by pkern (subscriber, #32883) [Link]

That's a valid option of course. However, if it's only a small bit of work you can save a bit of time on every invocation of the script, by using a faster shell than bash as `/bin/sh'. As long as you intentionally expect bash with its feature set for a script, it's fine to just write `/bin/bash' as your interpreter. This work is supposed to check for the accidental expectation that the POSIX `/bin/sh' has the bash feature set.

checkbashisms

Posted Dec 22, 2010 12:31 UTC (Wed) by epa (subscriber, #39769) [Link]

Or, just as well, declare /bin/sh to be bash and have
a separate /bin/minimal_bare_bones_sh for the tiny
number of cases where it is truly needed.

Fifteen years ago bash might have been seen as bloated.
That really isn't an issue any more.

checkbashisms

Posted Dec 25, 2010 5:07 UTC (Sat) by foom (subscriber, #14868) [Link]

POSIX sh is standardized. Regardless of what /bin/sh actually points to, or how bloated bash is or is not, if you write a script that depends on nonstandard extensions in bash, you should put #!/bin/bash at the top.

checkbashisms

Posted Dec 31, 2010 11:52 UTC (Fri) by epa (subscriber, #39769) [Link]

A little ironic that you use POSIX standardization as a reason for a particular shebang line, since the #! syntax is not part of POSIX at all.

I think you are probably right though - to keep everybody happy, if you want bash it's best to say what you mean.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds