Shell Programming Notes (III) __ programming

Source: Internet
Author: User

Variable permutation command permutation formula substitution reference use backslash implementation reference use single quotation marks with double quotes

variable Substitution

There are four forms of substitution for variable permutations
Syntax format: ${param:=word}
If the Param value is empty or unassigned, word replaces param as the return value of the expression, but does not change the value of param
Examples are as follows:

It is clear that the value of the myfruit variable is still empty and the value of the fruit variable becomes the Apple default value assignment
Syntax format: ${param:=word}
If the Param value is empty or unassigned, Word assigns its own value to Param
Examples are as follows:
Null value error
Syntax format: ${param:?msg}
When the variable param is unassigned or empty, an error message is printed. MSG to stderr
Examples are as follows:
a value substitution
Syntax format: ${param:+word}
If the variable param has a value, the variable word replaces Param as the return value of the expression, but the Param value is unchanged
Examples are as follows:
command Substitution

is to assign the output of a command to a variable as the value of a variable
Example:

Me? You can also direct the command substitution as an argument to another command:
Formula substitution

can help users complete basic integer operations in the shell
Syntax format $ ((expr))
Reference To implement a reference using a backslash


In fact, this backslash is to play an escape function, so that the characters with special meaning invalidation
The reference is escaped and there is no more to repeat here using single quotes

For an echo statement that contains many special characters, we can directly use single quotes to cause the statement to be output.
Use double quotes

The limitation of using single quotes is great, it escapes all the special symbols, which is not the problem with double quotes, and double quotes prohibit all metacharacters except $ and ' , and the commands that use inverted quotes ' are normally executed:

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.