问题描述:

I am trying to understand the Bash shell as an interpreter of the Bash language, from "3.1.1 Shell Operation" in Bash Reference Manual (see below).

If I am correct:

  • Interpretation consists of preprocessing, compilation and execution.

  • Compilation consists of lexical analysis, syntax analysis, semantics analysis, code generation, and code optimization.

If I am correct, step 2 is lexical analysis, step 3 is syntax analysis.

Do step 4 and step 5 for performing expansion and redirection belong to semantic analysis of compilation?

Thanks.

The following is a brief description of the shell’s operation when it

reads and executes a command. Basically, the shell does the following:

  1. Reads its input from a file (see Section 3.8 [Shell Scripts], page 39), from a string supplied as an argument to the -c invocation option

    (see Section 6.1 [Invoking Bash], page 80), or from the user’s

    terminal.

  2. Breaks the input into words and operators, obeying the quoting rules described in Section 3.1.2 [Quoting], page 6. These tokens are

    separated by metacharacters. Alias expansion is performed by this step

    (see Section 6.6 [Aliases], page 88).

  3. Parses the tokens into simple and compound commands (see Section 3.2 [Shell Commands], page 8).

  4. Performs the various shell expansions (see Section 3.5 [Shell Expansions], page 21), breaking the expanded tokens into lists of filenames (see Section 3.5.8 [Filename Expansion], page 30) and commands

    and arguments.

  5. Performs any necessary redirections (see Section 3.6 [Redirections], page 31) and removes the redirection operators and

    their operands from the argument list.

  6. Executes the command (see Section 3.7 [Executing Commands], page 35).

  7. Optionally waits for the command to complete and collects its exit status (see Section 3.7.5 [Exit Status], page 38).

相关阅读:
Top