Shebang
Description
A shebang or hashbang is a particular line that often begins
scripts. The line begins with the characters #!
. This line defines
which program should be passed the contents of the file. For
example:
#!/bin/sh echo "Hi there!"
/usr/bin/env
The paths in the shebang line may be different of different
machines. The env
program exists to solve this problem and make
scripts portable. This program looks in the user's $PATH
to find
the location of an application. The path /user/bin/env
is commonly
used for this utility.
#!/usr/bin/env sh echo "Hi there!"
Script Execution
Once a shebang line exists, the chmod
command can be used to make
a script executable.
chmod +x script.sh ./script.sh
The first line adds (+
) the executable (x
) permission to the
file.