The shell quotes
in the the shell often uses single quotes, double quotes, back quotes ( keys above the Tab key in the keyboard), backslashes ( meaning of some Shell metacharacters). If we sometimes want the echo command to output a character that contains the $ symbol itself, in general,the Shell will consider $ as the value of the variable, such as the case we need to use some features to block the $ symbol itself has a special meaning to make it revert to literal meaning.
1. Backslashes
backslashes can be followed by a single character as a literal character, such as * in the Shell to represent any character, in the search often use * to find multiple matching files, but it is possible that you need to find * The character itself, at this point,\* will use * as the letter meaning of the ordinary characters.
In addition, if you use \ carriage returnat the end of the command, \ can block the command-submission function of the carriage return, which will take the carriage return as a newline to continue the input command, implementing the multi-line input function of the command.
[[email protected] ~]# echo * # Displays a list of all files in the current directory
Anaconda-ks.cfginstall.log Install.log.syslog
[[email protected] ~]# echo \* # Display * characters
*
[[email protected] ~]# echo \> # display > symbols
>
[[email protected] ~]# find/\ # newline input multi-line command
> -name "test.txt" \
> -type f\
> -size+5m
2. Single quotation marks
single quotation marks can restore all the characters in the middle of it to a literal meaning, enabling masking the function of the Shell meta-character. Note that you cannot insert a single quotation mark in the middle of a two single quotation mark, and the single quotation mark must appear in pairs.
[[email protected] ~]# echo ' $HOME ' # single quotation marks will mask the special features of $
$HOME
[[email protected] ~]# echo ' test\ ' # default \ for escape wrapping, this is also blocked
Test\
3. Double quotes
double quotation marks are similar to single quotes, but they do not mask the meaning of metacharacters such as ',\ and $ ', if you need to mask the meanings of these characters, you must have a \ symbol in front of them, The functionality of other characters will be masked (including single quotes). That is, a single quotation mark between two double quotes does not have to be paired.
[Email protected] ~]# echo "This ' s book."
This ' s book.
[Email protected] ~]# echo "$HOME"
/root
[[email protected] ~]# echo "\ $HOME"
$HOME
4. Anti-Quote
The shell uses anti-quotes for command substitution, and command substitution enables the shell to Replace command characters with output from the command execution results. The same functionality can also be implemented using $ () .
[Email protected] ~]# echo "Today is ' date +%d '"
Today is 02/09/13
[Email protected] ~]# echo "Today is $ (date +%d)"
Today is 02/09/13
This article is from the "Ding Ding Adventures" blog, please be sure to keep this source http://manual.blog.51cto.com/3300438/1897846
Common quotes in the shell