Skip to content

How Commands Are Interpreted

ksherlock edited this page Jun 23, 2016 · 1 revision

To interpret a command, the MPW Shell’s command interpreter uses a set of
steps in a specified order, as illustrated in Figure 6-1.

Each step in the process is explained below. When it receives a command, the command interpreter takes the following steps:

1. Substitutes command names for command aliases.
The first thing the command interpreter does is scan the command for any words that are command aliases. When a command alias is found, it is translated to its original MPW Shell command.

2. Evaluates control structures.
The MPW Shell has various control structures, including the Begin ... End structure, the If ... Else ... End structure, the For ... End structure, and the Loop ... End structure. If the MPW Shell finds a control structure, it evaluates it at this point.

3. Evaluates variables and substituted commands.
The command interpreter replaces all variables, whether quoted or not, with their value. It also replaces all commands used as parameters to other commands with their output. If a command contains an ellipsis, the command interpreter opens the appropriate Commando dialog box and uses the resulting command as output.

4. Breaks the command line into a series of “words,” which are separated by spaces or tabs.The following special characters are considered separate words, whether or not they are separated by blanks:

Character Meaning
;         Join commands on one line
|         Pipe output
||        If not successful, do ... 
&&        If successful, do ... 
()        Group commands or expressions 
<         Redirect standard input 
>         Redirect standard output and replace 
>>        Redirect standard output and append 
≥         Redirect error messages and replace 
≥≥        Redirect error messages and append

5. Generates filenames.
If the command interpreter finds a filename pattern, it uses the pattern to generate a list of files. A filename pattern is a word that contains any of the following special characters not marked with quotation marks:
Character Meaning
?         Match any character 
≈         Match any string
[ ]       Specify a scan set
*         Zero or more occurrences
+         One or more occurrences
« »       Specify a repetition

6. Redirects input and output.
If the command interpreter finds an input or output redirection character, it interprets the character and prepares to redirect the command’s input or output.

Character Meaning
<         Redirect standard input
>         Redirect standard output and replace
>>        Redirect standard output and append
≥         Redirect error messages and replace
≥≥        Redirect error messages and append
∑         Redirect all output and replace
∑∑        Redirect all output and append

7. Executes the resulting command.
Any remaining single or double quotation marks are removed, and the command is executed.

Clone this wiki locally