2.5. Interpreting code
This section shows how to byte-compile a program written in Python and raw-interpret a program written in bash.
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.
pello.py
#!/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
Python is often byte-compiled, but not in the way described here. The following procedure aims not to conform to the community standards, but to be simple. For real-world Python guidelines, see Software Packaging and Distribution.
Use this procedure to compile pello.py
into byte code:
Procédure
Byte-compile the
pello.py
file:$ python -m compileall pello.py $ file pello.pyc pello.pyc: python 2.7 byte-compiled
Execute the byte code in
pello.pyc
:$ 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.
bello
#!/bin/bash printf "Hello World\n"
Programs written in shell scripting languages, like bash, are raw-interpreted.
Procédure
Make the file with source code executable and run it:
$ chmod +x bello $ ./bello Hello World