The difference between single quotes, double quotes, inverted quotes, and backslashes in a Linux shell _linux shell

Source: Internet
Author: User
Tags echo command
1. Single quotation mark (')

# grep Susan Phonebook
Susan Goldberg 403-212-4921
Susan Topple 212-234-2343
If we're looking for Susan Goldberg and can't use the grep Susan Goldberg Phonebook command directly, grep treats Goldberg and phonebook as files to search for
# grep ' Susan Gold ' phonebook
Susan Goldberg 403-212-4921
When the shell encounters the first single quotation mark, it ignores all the special characters that are followed up to the closing quotation mark.

2. Double quotation mark ("")

Double quotes are similar to single quotes, except that they are less stringent. Single quotes tell the shell to ignore all special characters, while double quotes only require ignoring the majority, specifically, the three special characters enclosed in double quotes are not ignored: $,\, ' that is, double quotes explain the special meaning of strings, Single quotes use strings directly. If you use double quotes to assign a string to a variable and feed it back to it, there is actually no difference between the direct feedback variable. Double quotes are often used if you want to query for strings that contain spaces.
# x=*
# echo $x
hello.sh menus.sh misc.sh Phonebook tshift.sh
# echo ' $x '
$x
# echo "$x"
*
This example shows the difference between an apostrophe, a single quote, and a double quote. In the last case, the double quotes tell the shell to replace the variable name in quotation marks, so the shell replaces $x with * because the double quotes do not replace the file name, so the * is passed to echo as the value to be displayed. For the first case to be further explained, the shell does not replace file names when assigning values to variables (as can be seen in the third case), the exact order in which each step takes place is as follows: The shell scans the command line and sets the value of x to Asterisk *;
The shell scans the command line again and touches the asterisk *, replacing it with the list of files in the current directory;
The shell initiates the echo command, passing the file manifest as an argument to echo.
The precedence of this assignment is important: The shell first replaces the variable, then the file name, and finally the line is processed as a parameter

3. Inverted quotation mark (')

Command substitution means that the shell can insert the standard output of a command into a command line anywhere. There are two methods in the shell for command substitution: to enclose the shell command in reverse quotes or $ (...) Structure, where, $ (...) The format is supported by the POSIX standard and is also nested.
# echo the date and the ' date '
The date and the 36-month 06:10:35 CST 2005
# echo Your Current working directory is $ (PWD)
Your Current Working Directory Is/home/howard/script

4. Anti-slash backslash-escaped (\)

A backslash is generally used as an escape character, or an escape character, and Linux if Echo wants the escape character to work, the-e option is used, and the escape character uses double quotes

Echo-e "\ n"

Another effect of the backslash is that when the backslash is used for the last character in a line, the shell takes the backslash of the end of the line as the continuation line, which is often used when entering long commands in several lines.
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.