主页 Swift UNIX C Assembly Go Plan 9 Web MCU Research Non-Tech

The difference between executable programs and scripts

2023-06-10 | Research | #Words: 832

What is an executable program?

Structurally, an executable program is a program composed of machine language (that is, a bunch of 1s and 0s) that the machine can recognize and execute.

Functionally, it processes the input in a specific way and then outputs the result processed.

In terms of file format, the current mainstream executable program format is PE (Portable Executable File Format) in Windows, and the abbreviation of “Executable” is the well-known EXE by many people; in macOS, the executable program is called Mach-O executable file.

Interpreter

Before introducing the script, you need to understand the “interpreter” (also called “interpret program”) and the difference between it and compiler.

The interpreter will process it based on the source program and user input, and then output the processed results. The most classic interpreters are various shells, such as bash, zsh. The source program is the script written in the script language corresponding to the interpreter. They are only processed by the interpreter and will not be compiled for mechine.

The difference between interpreter and compiler

Interpreters and compilers are often compared together, because both are designed to allow users to input and obtain processed results. Interpreter itself can accept input, process and output results, and the compiler will eventually generate an executable program, and then this executable program will accept input, process and output results.

Generally, the compiler can bring faster speed, and the interpreter can bring better error message diagnosis. Because the interpreter is run part by part, the error message returned can be accurate to the line or even the column, while the compiler often just tells you which file has problems.

However, the current compiler (not referring to the tool set) also has very good error message diagnosis. If you use some tools or IDE, you can even interrupt the script at any time, so the benefits of scripts are generally only convenience (perhaps for some exams will mention the “Better Error Message Diagnostics”).

The distinction between scripts and executable programs is an important point in understanding compilers. Java is a mixture of the two. Which part is the compiler and which part is the interpreter?

Let me make a digression here to assist understanding: Some people think that writing scripts is not programming because there is no “compile”, which is the process of compiler processing.

What is script

The script was mentioned above: a script is the code that the interpreter can execute. The code for different interpreters executing is different script languages.

The script language is an input content, and then lets the interpreter process the input content and process. The input content will not be converted into code can executed by machine.

For example, the following bash script is used to compile and run a C language program, finally delete the generated executable program.

#!/bin/bash

cc $1

./a.out

rm a.out

This script will generate an executable program, but is this executable program generated by a script? No, the script calls the cc program to generate it, and the deletion also calls the rm program to delete it.

The difference between executable programs and scripts

After reading the above, you will find that the often mentioned “programming” actually do not only refer to programs compiled from languages ​​such as C, but also include writing scripts.

Both are actually executable programs.

First of all, both require running permissions, but the execution subjects are different: the former is the machine, and the latter is the interpreter.

So why are both programs?

Let’s learn a little English literal: The word “program” may seem familiar to you, but can you try to explain it? This word has many meanings in English dictionaries. Here are two that need to be distinguished:

a complete plan for solving a problem by the use of a mechanism (such as a computer)

a complete plan for solving a problem by the use of a mechanism (such as a computer) that includes both instructions to be inserted into the mechanism and plans for human activities such as interpreting output

The first explanation is the common meaning of “program”; the second explanation is rare and difficult to understand. It is a set of processes, and the “program” in the computer is just one of its meanings.

Therefore, things written in scripting languages are also called programs, which corresponds to the second explanation above. Of course, “program” here may be more appropriately translated as “process”. Now we call it “script”, which can better distinguish between the two. In the history of computer science, many terms have been changed, and finally it is called this because of some chance.

In other words, the executable program that is compiled and formed is called an “executable file”, and if it is executed by an interpreter, it is called a “script”.

I hope these will help someone in need~