Lecture
Command interpreter, command-line interpreter — a computer program, part of the operating system, that provides basic means of controlling the computer through interactive entry of commands via a command-line interface or through sequential execution of batch command files.
As a rule, its functions boil down to letting the user launch other programs; it may also contain some basic input/output commands and its own simple scripting language.
The MS-DOS and Windows 95 operating systems include the command interpreter COMMAND.COM, Windows NT includes cmd.exe, and in OS/2 the command interpreter is also called cmd.exe; the most widespread command interpreter in Linux and FreeBSD is bash, besides which there is a large family of others.
As a rule, when configuring an OS at a low level, the user has the ability to change the default command interpreter.
The functions of a command-line interpreter include:
A command-line interpreter often provides loops, conditional and unconditional jump statements, and variables. It allows you to write both simple scripts for automating everyday tasks and quite complex programs.
An example of a calculator for the Windows/MS-DOS command-line interpreter.
@echo off :begin Cls Title Calculator Color 71 Echo Enter an equation: Set /P exp= Set /A result=%exp% Title Calculated Echo Your equation: %exp% Echo Solution: %result% Pause>nul goto begin
A calculator for the bash shell:
#!/usr/bin/env bash echo "Calculator" while read -p "Enter an expression: " expr do echo "Result: $(($expr))" done
The shell operates on simple commands.
A simple command is a sequence of words separated by spaces. Pressing the Enter key when entering a command, or a line break when processing a script, is the signal to the command interpreter that the command is complete. It is then processed and executed.
A pipeline is a sequence of one or more commands separated by |(& for cmd.exe). The standard output stream of each command, except the last, is connected by a pipe to the standard input stream of the next command. Each command is executed as a separate process; the interpreter waits for the last command to finish. The exit status of a pipeline is the exit status of its last command. Here is an example of a simple pipeline for the bash interpreter:
$ ls | tee save | wc
15 15 100
DOS:
Windows:
Unix:
Direct mode, also known as immediate mode , is a computing term referring to the entry of text commands outside the context of a program. The command is executed immediately and the results are displayed on the screen, unlike programming mode, in which nothing is executed until a specific command is given. (BASIC's RUN is an example of a direct-mode command.) Some commands can be used in either mode, while others were exclusively one or the other.
Direct mode was most often used on 8-bit systems such as the Commodore 64 and Atari 800 series, although commands entered in a Unix shell can be regarded as the direct-mode equivalents of shell scripts, and modern interpreted languages such as Python and Perl include REPL shells in which commands can be entered for immediate evaluation and execution.
Modern integrated development environments also often offer a direct mode in which, during debugging and while program execution is paused, commands can be executed directly in the current scope and the result is shown on the monitor.
Indirect mode:
10 PRINT "intellect.icu"
READY RUN HELLO intellect.icu READY Direct mode:
PRINT "HELLO intellect.icu" HELLO intellect.icu
READY
REPL (from English read-eval-print loop) is a form of organizing a simple interactive programming environment within the means of a command-line interface. This abbreviation most often characterizes the interactive environment of the Lisp programming language, but this form is also typical of the interactive environments of Erlang, Groovy, Haskell, Java, JavaScript, Perl, PHP, Python, Ruby, Scala, Smalltalk, Swift, and other languages.
In such an environment, the user can enter expressions, which the environment immediately evaluates, displaying the result of the evaluation to the user. The names of the elements of the loop are related to the corresponding Lisp primitives:
read reads one expression and converts it into the corresponding data structure in memory;eval takes one such data structure and evaluates the corresponding expression;print takes the result of evaluating the expression and prints it for the user.To implement a REPL environment for a given language, it is enough to implement three functions, for reading, evaluation, and printing, and to combine them in an infinite loop. A REPL environment is very convenient when learning a new language, since it gives the user quick feedback.
Comments