The difference between single quotes, double quotes, and anti-quotes (' ') in the Linux Bash shell, and the differences between the various brackets

Source: Internet
Author: User
Tags arithmetic

One, single and double quotation marks

First, both single and double quotes are meant to solve the problem of having spaces in the middle.

Because the space in Linux as a very typical delimiter, such as String1=this is astring, so execution will be error. To avoid this problem, single and double quotes are generated. The difference is that single quotes deprive them of the special meaning of all the characters, while the ' $ ' (parameter substitution) and ' ' (command substitution) in double quotes are exceptions. So, there's basically no difference between the two, unless the parameter substitution $ and the command substitution are encountered in the content.

So here's the result:
Num=3
Echo ' $num '
$num
echo "$num"
3
Therefore, if you need to use both of these symbols in the double quotation mark "", you need to escape with a backslash.

Second, anti-quote "'

The usage of this thing, I Baidu a bit, and $ () is the same. When you execute a command, the statements in either, or $ () are executed once as a command, and the result is added to the original command for re-execution, for example:
echo ' ls '
The LS is executed first to get xx.sh and so on, then replace the original command as:
Echo xx.sh
The result of the final execution is
xx.sh
Well, usually we encounter the output of a bunch of command execution results into a variable, it needs to be enclosed in this command substitution, it is understandable.
There is another problem here, although many system engineers like to use anti-quotes to enclose the command when using the Replace function. However, according to the POSIX specification, a system engineer is required to take the form of a $ (command). So, we'd better follow this specification, less ", more than $ ()

Three, parentheses, brackets, and curly braces differ

So, here's another question, the difference between parentheses, brackets, and curly braces.
First, the difference between parentheses and curly braces. The two are, in fact, the concept of "command group", which is commandgroup.
() put command group in Subshell to execute, also called nested Sub-shell.
{} is done inside the same shell, also known as Non-namedcommand Group.
So, if you execute "function" inside the shell, you need to use {}, which is actually a command group.
However, according to the measurements, test=$ (LS-A) can execute, but the test=${ls–a} syntax is wrong. The estimate is also related to the reasons mentioned above.

In addition, the differences from the online excerpt are as follows:
A, () just re-open a sub-shell for a sequence of commands to execute
b,{} Executes a string of commands in the current shell
C, () and {} All put a string of commands inside the parentheses, and the commands are separated by a number;
D, () The last command can be used without a semicolon
e,{} The last command to use a semicolon
f,{} must have a space between the first command and the opening parenthesis
G, each command in () does not have to have spaces in parentheses
H, () and the redirection of a command inside the {} brackets only affects the command, but redirects outside the brackets affect all the commands in the parentheses

Two brackets (()), which represent arithmetic expansions, are standard arithmetic calculations for what they include-note that floating-point numbers cannot be counted, and if a floating-point number is required, it needs to be done in BC.

As for the brackets [], the sensory function is used to compare. For example, in the IF statement inside, while statement inside, and so on.
This leads to the [..] and [[...]] The difference: (from an online, measured confirmation): use [[...]] The conditional judgment structure, rather than [...], prevents many logic errors in the script. For example, &&, | |, <, and the > operator can normally exist in [[]] conditional judgment structures, but if it appears in [] structure, it will be an error.

The difference between single quotes, double quotes, and anti-quotes (' ') in the Linux Bash shell, and the differences between the various brackets

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.