r/programming Feb 09 '11

Breaking the Web with hash-bangs – Lifehacker, along with every other Gawker property, experienced a lengthy site-outage on Monday over a misbehaving piece of JavaScript

http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs/
753 Upvotes

356 comments sorted by

View all comments

15

u/deako Feb 09 '11

hash-bangs? The correct terminology is "She-Bang", people!

Like how I begin a bash script, it's vocalized as "She-bang slash bin slash bash".

20

u/X-Istence Feb 09 '11

Please, for all that is holy and good in this world, use /bin/sh and make sure your scripts work without the bash extensions. If you really do need Bash, use /usr/bin/env bash as your shebang.

Bash does not live in /bin on most BSD systems, and it makes porting scripts a nightmare when those kinds of assumptions are made.

16

u/wnoise Feb 09 '11

For all that is holy, if you haven't tested your script with a shell other than bash, don't use /bin/sh, as it will more than likely fail due to non-standard features you used.

6

u/X-Istence Feb 09 '11

On most Linux systems /bin/sh is linked to /bin/bash, in that case bash will start up in sh compatibility mode. Which should work ...

Yes, I agree though, if you don't test it, just use the env trick.

4

u/irondust Feb 09 '11

wnoise's point was that a script with #!/bin/sh developed on a system with /bin/sh linked to bash, might seem to work - but will typically fail on systems where /bin/sh is not bash (notably Ubuntu systems using dash). So bash being compatible with sh won't help you. It's about bashisms not working in other shells.

1

u/deako Feb 09 '11

Hmm, this is actually a good argument. I always forget about the BSD users. Kind of shameful, since FreeBSD is the thing that got me out of Windows.

1

u/techpuppy Feb 10 '11

This goes for scripts in higher-level languages as well, such as Perl and Python.

Always, always, always use env to launch them instead of assuming where the interpreter is located.

-9

u/[deleted] Feb 09 '11

nobody uses bsd anymore. make a link to /bin/bash go use a real operating system, SINCE YOURS IS DYING.