Linux Shell Programming (ii): Shell syntax

Source: Internet
Author: User

Shell syntax Shell performs command operation

When the shell reads the input, it performs a series of actions. If the input represents the beginning of a comment, the shell ignores the comment symbol (' # ') and the remainder of the line.

When the shell reads and executes the command, the following actions are taken:

    1. Reads its input from a file (shell script), from the string as a parameter to the "-C" invocation option (called bash), or from the user's terminal.
    2. Splits the input into words and operators, adhering to the referenced rules described. These tokens are delimited by metacharacters. This step performs an alias extension.
    3. The token is parsed into a simple compound command.
    4. Perform various shell extensions to break the extension tokens into filenames, commands, and argument lists.
    5. Performs any necessary redirects and removes the redirect operator and its operands from the parameter list.
    6. Execute command
    7. Optionally, wait for the command to complete and collect its exit status.
References (quoting)

References are used to remove certain characters or words from a particular meaning to the shell. References can be used to disable special handling of special characters, prevent reserved words from being recognized, and prevent parameter extensions. Each shell metacharacters has a special meaning for the shell and must be referenced to represent itself.

  • There are three reference mechanisms: escape characters, single quotes, and double quotes.
Escape character

A non-referenced backslash "\" is a bash escape character. It retains the literal value of the next character.
Use:

  1. Convert ordinary characters to special use to indicate characters that cannot be displayed directly, such as back keys, enter, etc.
  2. Used to convert a character of a special meaning back to its original meaning.
Single quotation marks

Single quotes usually end with ' start with ' and often store strings between two single quotes. Single quotation marks cannot appear in an expression that is closed with single quotation marks, for example: A= ' I m so hot '; the system will error. You can use escape characters to escape single quotes, for example: a= ' i\ ' so hot '; the above statement will not error.

Double quotes

Similar to single quotes, double quotes can also be used to store strings, double quotes must be escaped in order to exist with the expression test, single quotation marks can be used between, when the "$" symbol appears in the double quotation marks, the shell will try to explain the variable or expression, the name of the variable to the following word. And single quotes don't explain variables and expressions

Comments

The shell takes "#" as the comment symbol. Commonly used in shell files (in shell scripts), when a line of a file appears with the symbol "#", "#" After the end of the line, will be ignored by the shell.

Syntax of the command

In the shell, the command format is: Command + arguments, commands and arguments are separated by spaces, and parameters and parameters are separated by spaces.
Such as:
>echo 1 2 3 4 5

View command Help information
  1. Using the parameter-H | --help. Most commands in the Shell support: command--help|-h to see instructions for using commands
  2. Use the man command: Man command to view details of the man manual for the command.
  3. Use Whatis:whatis to display a description of the command
View the use Help for Shell built-in commands (BUILTIN)

Use the Help command to view the use of built-in commands
Displays a short summary of the build command. If a pattern is specified, detailed help is provided on all command-matching modes, otherwise a list of Help topics will be printed.

Such as:

[[email protected] ~]# help truetrue: true    Return a successful result.    Exit Status:    
Use the Info command to view information format documents

Use the info command to view a command's details document, such as commands such as Bash,gawk,sed,grep, which you can use the Info command to view its detailed usage documentation.

Linux Shell Programming (ii): Shell syntax

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.