Home  >  Article  >  Operation and Maintenance  >  What is the difference between single quotes and double quotes in linux

What is the difference between single quotes and double quotes in linux

青灯夜游
青灯夜游Original
2021-11-23 10:54:0710282browse

Difference: Single quotation marks are strong references, which will ignore the special processing of all quoted characters, and the quoted characters will be used intact; while double quotes are weak references, which will Some quoted characters are treated specially. To put it simply, single quotes directly output the internal string without parsing special characters; special characters within double quotes will be parsed.

What is the difference between single quotes and double quotes in linux

#The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.

1. Single quotation mark

Single quotation mark is a strong quotation. It will ignore the special processing of all quoted characters and be quoted. The characters will be used intact. The only thing to note is that they are not allowed to quote themselves;

single quotes treat the contents as strings, ignoring all commands and special characters, similar to Usage of a string

echo 'This is a string'
>>> This is a string
echo 'ls ./'
>>> ls ./

2. Double quotation marks

Double quotation marks are weak references, which will affect some Quoted characters are treated specially.

The difference between double quotes and single quotes is that they can contain special characters (single quotes directly output the internal string and do not parse special characters; special characters will be parsed within double quotes), including ', " , $, \, if you want to ignore special characters, you can use \ to escape, ignore the special characters, and output them as ordinary characters:

var = 1
echo '$var'
>>> $var
echo "$var"
>>> 1

echo "Here 'this is a string' is a string"
>>> Here 'this is a string' is a string
echo "Here \"this is a string\" is a string"
>>> Here "this is a string" is a string

3. Backticks

Backticks are used to include a command string. The command will be executed first, and the result will be returned to the layer command before execution:

echo `echo 'this is the inner string'`+'out' 
>>> this is the inner string+out
echo `echo 'this is the inner \` string'`+'out'    #转义反引号
>>> this is the inner ` string+out

Backticks are similar to $(command).

#一个使用例子,如果想要遍历当前文件夹及其一级子文件夹:
ls $(ls) 
ls `ls`
>>> first_folder
>sub_1 ..sub_2
> second_folder
>sub_1 ..sub_2
>

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is the difference between single quotes and double quotes in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn