Shebang (Unix) - Purpose

Purpose

Interpreter directives allow scripts and data files to be used as system commands, hiding the details of their implementation from users and other programs, by removing the need to prefix scripts with their interpreter on the command line.

Consider a Bourne shell script that is identified by the path "some/path/to/foo" and that has the following as its initial line:

#!/bin/sh -x

If the user attempts to run this script with the following command line (specifying "bar" and "baz" as arguments):

some/path/to/foo bar baz

then the result would be similar to having actually executed the following command line instead:

/bin/sh -x some/path/to/foo bar baz

If "/bin/sh" specifies the Bourne shell, then the end result is that all of the shell commands in the file "some/path/to/foo" are executed with the positional variables $1 and $2 set to "bar" and "baz", respectively. Also, because the initial number sign is the character used to introduce comments in the Bourne shell language (and in the languages understood by many other interpreters), the entire shebang line is ignored by the interpreter.

However, it is up to the interpreter to ignore the shebang line; thus, a script consisting of the following two lines simply echos both lines to standard output when run:

#!/bin/cat Hello world!

Read more about this topic:  Shebang (Unix)

Famous quotes containing the word purpose:

    Satire exists for the purpose of killing the social being [for the sake of] the true individual, the real human being.
    —D.H. (David Herbert)

    Happiness serves hardly any other purpose than to make unhappiness possible.
    Marcel Proust (1871–1922)

    Some of my friends spoke as if I was coming to the woods on purpose to freeze myself.
    Henry David Thoreau (1817–1862)