Execution directive for unix scripts
more from info
Sep 1, 06

If you've ever written a unix command line script, you know it has to start with #! followed by a path to an executable. For shell scripts, you'll specify the path to the shell in which you want your script to run, like: #!/bin/sh for Bourne shell, or #!/usr/bin/perl for Perl.

I used to use vi to help me out with :r!which sh. So when you type :r!which sh in your vi window, you'll see the evaluated result in your editor (namely, "/bin/sh"). Not bad, and makes it easy to handle updates when scripts move to different machines.

But here's a nice shortcut:

#!/usr/bin/env sh, or
#!/usr/bin/env ruby, or
#!/usr/bin/env perl

So now I only have to remember one path (/usr/bin/env), my scripts just got more portable across different machines, and are no longer tied to path constraints in my local shell.