[Shell Scripting] “Shebang” (#! /bin/bash) followed by a space is optional

I do not remember where I read this, but for some time I thought it was always a better convention to follow the “shebang”, #!, interpreter directive with a space before specifying your binary to be executed by the OS, for example:

#! /usr/bin/env perl -cw
...

This caveat was brought up by a colleague of mine while looking at a perl script of mine. They had never seen someone beginning their script with a space in between the “shebang” and the slash and thought it unconventional, which it probably is. But, according to Dennis Richie (RIP) via wikipedia it is harmless and does not matter if there is a space or not:


#! /bin/sh

at the left margin of the first line of your shell scripts.
Blanks after ! are OK. Use a complete pathname (no search is done).
At the moment the whole line is restricted to 16 characters but
this limit will be raised.

See Also (Blank after #! required?)

Advertisements
This entry was posted in *Nix. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s