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. The interpreter executes the commands from the file line-by-line (one at a time).

So, instead of typing out the commands we need to run, we can, instead, place all of the commands in a script file and then run the file! This is especially helpful for complex commands that you run regularly.

One important use case for CSCI 1302 is creating a script to compile all of the Java code in your assignment/project and then subsequently run the driver program. Imagine not having to type out each javac and java command each time while remembering the appropriate ordering of dependencies!

Just remember, interpreter scripts are not limited to commands related to Java. We can include any valid Unix command!

There are many types of interpreter scripts for various programming languages. In 1302, we will use interpreter scripts for commands used in the Bash shell (the program that interprets the commands we type on Odin). In this case, we usually call these types of scripts shell scripts since they work on a specific shell and contain our Unix commands.

An interpreter script needs to satisfy the following requirements:

  • The file’s execute permission must be enabled (More in the next section)

  • The first line in the file is the location of the interpreter (Bash for us) in 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”).

We will see specific examples we can use on Odin in the next section.