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

青灯夜游
Release: 2021-11-23 10:54:07
Original
10285 people have browsed it

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 ./
Copy after login

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
Copy after login

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
Copy after login

Backticks are similar to $(command).

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!