6.1. What is an Interpreter Script?

An interpreter script is a regular text file that contains a sequence of commands that should be executed by some interpreter program. Instead of launching the interpreter, typing out the commands (or launching it with input redirection), we can, instead, place all of the commands in a script file.

An interpreter script needs to satisfy the following requirements:

  • The file’s execute permission must be enabled (to whoever will use it); and

  • The first line in the file is of the form:

    #! interpreter [optional-arg]
    

    Historically, this first line is known as a shebang since it starts with the number sign, sometimes called the “sharp” symbol or “hash” tag, followed by an exclamation mark (or “bang”).

The interpreter must be a valid path to an executable program which is not typically itself a script (although it can be). When executed, the interpreter is invoked with the following command-line arguments:

interpreter [optional-arg] filename arg...

The remaining text in the script file is executed in the invoked interpreter.