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:

    The moment a mere numerical superiority by either states or voters in this country proceeds to ignore the needs and desires of the minority, and for their own selfish purpose or advancement, hamper or oppress that minority, or debar them in any way from equal privileges and equal rights—that moment will mark the failure of our constitutional system.
    Franklin D. Roosevelt (1882–1945)

    When one pays a visit it is for the purpose of wasting other people’s time, not one’s own.
    Oscar Wilde (1854–1900)

    War is an ugly thing, but not the ugliest of things: the decayed and degraded state of moral and patriotic feeling which thinks nothing worth a war, is worse.... A war to protect other human beings against tyrannical injustice; a war to give victory to their own ideas of right and good, and which is their own war, carried on for an honest purpose by their own free choice—is often the means of their regeneration.
    John Stuart Mill (1806–1873)