When writing shell scripts or other types of executables, you often put a directive at the top of the file to indicate which kind of interpreter to use.
Oh wait, that didn’t work?
Okay, that worked on my Mac. But why all the guesswork? There is another command that is better.
env. Use it as a directive like so:
And if it’s a
env is kinda like
which. It takes the first argument and figures out the full path of that, and uses it as the directive
man env to read more about it.
#!/usr/bin/env INTERPRETER makes your script more portable
the ability to run your script anywhere, on any OS/platform
The holy grail goal of programming/CS = write once, run everywhere
It is somewhat circular in that it depends on
env living inside of
/usr/bin/, but I believe it is a convention that is much more rarely broken than where
another CS vocab word.
The quality of being predictable, doing expected things.
e.g you walk into a dark room, you expect the light switch to be near the doorway opposite of the door hinge, not a mousetrap clamping down on your fingers when you reach along the wall.