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:
- 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.
- 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.
- The token is parsed into a simple compound command.
- Perform various shell extensions to break the extension tokens into filenames, commands, and argument lists.
- Performs any necessary redirects and removes the redirect operator and its operands from the parameter list.
- Execute command
- 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:
- Convert ordinary characters to special use to indicate characters that cannot be displayed directly, such as back keys, enter, etc.
- 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
- Using the parameter-H | --help. Most commands in the Shell support: command--help|-h to see instructions for using commands
- Use the man command: Man command to view details of the man manual for the command.
- 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