2.5. Interpreting code
In the two examples below, the
#! line at the top of the file is known as a shebang, and is not part of the programming language source code.
The shebang enables using a text file as an executable: the system program loader parses the line containing the shebang to get a path to the binary executable, which is then used as the programming language interpreter. The functionality requires the text file to be marked as executable.
2.5.1. Byte-compiling code
This section shows how to compile the
pello.py program written in Python into byte code, which is then executed by the Python language virtual machine.
Python source code can also be raw-interpreted, but the byte-compiled version is faster. Hence, RPM Packagers prefer to package the byte-compiled version for distribution to end users.
#!/usr/bin/python3 print("Hello World")
Procedure for byte-compiling programs varies depending on the following factors:
- Programming language
- Language’s virtual machine
- Tools and processes used with that language
Use this procedure to compile
pello.py into byte code:
$ python -m compileall pello.py $ file pello.pyc pello.pyc: python 2.7 byte-compiled
Execute the byte code in
$ python pello.pyc Hello World
2.5.2. Raw-interpreting code
This section shows how to raw-interpret the
bello program written in the bash shell built-in language.
#!/bin/bash printf "Hello World\n"
Programs written in shell scripting languages, like bash, are raw-interpreted.
Make the file with source code executable and run it:
$ chmod +x bello $ ./bello Hello World