In bash, $, * 、?、 [,], ', ', ', \, have special meanings. Similar to the compiler's pre-compilation process, bash, in the process of scanning the command line, will first interpret all the special characters at the text level, and then make the kernel system calls to the new command line that completes the conversion.
Where the anti-quote is similar to a function call, not just a simple text substitution and matching.
The part of the command line that is enclosed in quotation marks, where all the special characters are interpreted according to ordinary characters;
The double quotation marks refer to the part that only interprets $ (dollar sign), \ (except \ n \ t), ' (anti-quote), and the interpreted text is processed only in plain text (the same single quotation mark).
The inverse quotation marks are equivalent to the command substitution, the reference part takes precedence, the running result is replaced with the outer command line text, the anti-quotation marks can be nested, but the inner inverted quotation marks must be escaped with \
Backslashes are used for command wrapping, as well as for echo-e interpretation.
Common examples of various articles on the Web, the second line focuses on:
# x=*
# echo $x This line performed two substitutions, replaced $x with *, and replaced * with the text of all the file lists in the current directory.
The text is assigned to echo as a parameter (bash automatically overrides the hierarchy by priority)
hello.sh menus.sh misc.sh Phonebook tshift.sh
# echo ' $x ' $x without any explanation, assign the text ' $x ' as a parameter to echo
$x
# echo "$x" $x is replaced with *, but because in double quotes, * does not replace, so the text "*" is assigned as a parameter to echo
*
Tips:
Most Linux distribution default shell is bash, query the current host all Shell can execute the following command:
$ cat/etc/shell
More than 40 commands are integrated within bash, and the general format is:
$ command [-options] [parameters]
Where, "-" is followed by the single-character option, "--" after the complete word option. In general, a function of the command (feature) supports both single-character options and the corresponding multi-char option.
In bash, * 、?、 [,] have special meanings for character matching. * represents 0 to more characters,? Represents a single character. [] is used to match a single character, internally with a dash to indicate the matching range of characters in ASCII order, or to enumerate all characters to be matched.
It is also important to use quotation marks when writing shell scripts, where you can summarize the characteristics of the three types of quotes.
1, single quotation marks ("), the contents of the enclosed quotation marks are treated as strings, even if a newline like \ n is done, it will also output \ nthe line instead of wrapping. 2, double quotation marks (""), and single quotes are different, double quotation marks will be wrapped in the contents of the escape character output. Here's an example: [JavaScript] $ Name=kehr $ echo "$name" Kehr $ Echo ' $name ' $name can clearly see the difference between the two 3, Kohiki (") This symbol does not know what the scientific name, I call it" Kohiki ", haha. What it does is that the contents of the Kohiki package will be executed first. For example, when we install files such as kernel devel, we use the following command: [HTML] yum install kernel-devel-' uname-r ' Here the Kohiki number is the keypad number 1, the left side of the key.
Single quotation mark (') Double quotation mark (") and back quotation mark (·) in the shell