Linux bash shell Learning (20): Command Line Processing

Source: Internet
Author: User

 

This article is also the seventh chapter of "Learning the bash Shell" 3rd Edition, "Input/Output and Command-Line Processing", four of the Reading Notes. Our goal is to read books thin. We will examine how the Linux system parses bash.

 

Step 1
: The command is assigned as a token based on spaces, tabs, NEWLINE,;, (,), <,>, |, and &.

Step 2
: Check whether the first token has some keywords, whether it is quotation marks, and whether '/' is a symbol to be combined, such as '{' or '(' to see if you need to read the next line of command, if necessary, go back to step 1st, so that the loop continues until the complete command is obtained. If it is not the start of the combined command, but other keywords, such as the end fi, report a syntax error. If not, go to step 1.

Step 3
: Check the 1st tocken of the command according to the alias list. It gets the alias correspondence and returns to step 1st. Go back to Step 1 and allow alias nesting. A represents B, B represents C, and alias represents the beginning of some integration commands.

Step 4
: Braces. For example, resolve a {B, c} to AB ac.

Step 5
: Wave number (~) Parsing, if at the beginning of a word, it is interpreted as the $ HOME directory path of the user.

Step 6
: Parameter Parsing. If the word starts with $, parse this parameter variable.

Step 7
: Whether to generate command replacement for $ parsing.

Step 8
: Performs mathematical operations on the format of $ (string.

Step 9
: After several steps starting from step 1, separate words again and use $ IFS as the separator.

Step 10
: Path name processing, wildcard processing, including *,?, /.

Step 2
: Check the command according to the first word of the command. The priority is a function command, builtin, and $ PATH command.

Step 2
: Execute the command after setting redirection I/O

This is only some of the steps, not all. An example is provided for further explanation. Before executing this command, you can use alias ll = "ls-l ". The user directory is/home/alice, and the $ value is 2537. Run ll $ (type-path cc )~ Alice/. * $ ($ % 1000.

  1. Ll

    $ (Type

    -Path

    Cc)

    ~ Alice/. * $ ($ % 1000 ))

    Words

  2. Ll

    It is not keyword, so the second step does not need to process any

  3. Ls

    -L

    $ (Type

    -Path

    Cc)

    ~ Alice/. * $ ($ % 1000 ))

    Replace ls-l with the alias "ll". This will repeat Step 1 to step 3.

  4. Ls

    -L

    $ (Type

    -Path

    Cc)

    ~ Alice/. * $ ($ % 1000 ))

    Do not process any

  5. Ls

    -L

    $ (Type

    -Path

    Cc)

    /Home/alice/. * $ ($ % 1000 ))

    To parse the path ~ Alice resolves/Home/alice

    .

  6. Ls

    -L

    $ (Type

    -Path

    Cc)

    /Home/alice/. * $ (2537% 1000 ))

    Concatenates $ to 2537. Learn how to use $ later.

  7. Ls

    -L

    /Usr/bin/cc

    /Home/alice/. * $ (2537% 1000 ))

    Run the command to replace "type-path cc ".

  8. Ls

    -L

    /Usr/bin/cc

    /Home/alice/. * 537

    Perform arithmetic operations.

  9. Ls

    -L

    /Usr/bin/cc

    /Home/alice/. * 537

    No processing is performed in Step 9.

  10. Ls

    -L

    /Usr/bin/cc

    /Home/alice/. hist537

    Replace the wildcard with the file name. * 537.

  11. In/Usr/bin

    To obtain the ls command

  12. /Usr/bin/ls

    Is executed with option-l and two parameters

Link: Me
Linux operations related articles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.