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:

    Productive collaborations between family and school, therefore, will demand that parents and teachers recognize the critical importance of each other’s participation in the life of the child. This mutuality of knowledge, understanding, and empathy comes not only with a recognition of the child as the central purpose for the collaboration but also with a recognition of the need to maintain roles and relationships with children that are comprehensive, dynamic, and differentiated.
    Sara Lawrence Lightfoot (20th century)

    The technologist was the final guise of the white missionary, industrialization the last gospel of a dying race and living standards a substitute for a purpose in living.
    Max Frisch (1911–1991)

    As peace is the end of war, so to be idle is the ultimate purpose of the busy.
    Samuel Johnson (1709–1784)