Anatomy of related commands in shell scripts

Source: Internet
Author: User

the difference between the ' and $ ' ():

In Bash, $ () and "(anti-quote) are used for command substitution.
Command substitution is similar to variable substitution, which is used to reorganize the command line, complete the command line in quotation marks, and then replace the result with the new command line.

Two commands achieve the same effect, but $ () is recommended for the following reasons:

    • 1, "Easy and" confused, especially for beginners.

      2, in the multi-level compound substitution, "must have the extra jump-off processing (backslash), while $ () is more intuitive."

The disadvantage of $ () is that not all UNIX-like systems support this approach, but the anti-quotes are definitely supported.

The difference between the two is seen in the example:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/85/91/wKioL1eoomDRwQ2NAAAcQ28Sbtk245.png-wh_500x0-wm_3 -wmp_4-s_2597127809.png "title=" Qq20160808220731.png "alt=" Wkiol1eoomdrwq2naaacq28sbtk245.png-wh_50 "/>

As you can see from the example:

    1. \$ in the inverted quotation mark does not convert the special meaning of $ to the contents of the anti-quote echo \ $hostname is still interpreted as an echo $HOSTNAME takes the value of the variable and outputs it.

    2. $ () on the contrary, $ is obviously escaped to a normal character, so it does not take the value of the variable, but returns the meaning of the string itself, and returns the $hostname.

    3. Conclusion:

The anti-quotation marks themselves are escaped by themselves, preserving the meaning of the alignment itself, and if we want to play a special meaning in the anti-quote, we must use 2 \ to represent it. $ () does not need to consider the problem, as we normally use.

Eval directive:

The EAVL command will first scan the command line for all permutations before executing the command. This command applies to variables that scan for a time that does not function. This command scans the variable two times. These variables, which need to be scanned two times, are sometimes referred to as complex variables. But the variables themselves are not complicated. The command can also be used to echo a simple variable, not necessarily a complex variable.

1. The eval command can also be used to echo simple variables, not necessarily complex variables.

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/85/91/wKioL1eoonuAgcBOAAAniYe0Q1Q570.png-wh_500x0-wm_3 -wmp_4-s_27648046.png "title=" Qq20160808221932.png "alt=" Wkiol1eoonuagcboaaaniye0q1q570.png-wh_50 "/>

2. Execute the command containing the string.

First we first create a file named Test that contains some text in this file. Next, assign the cat test to the variable file, and now we echo the variable to see if we can execute the above command.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/85/91/wKiom1eoopnxmMlpAAA5MOYfCHQ043.png-wh_500x0-wm_3 -wmp_4-s_2678177081.png "title=" Qq20160808222516.png "alt=" Wkiom1eoopnxmmlpaaa5moyfchq043.png-wh_50 "/>

As you can see from the above results, you can use the Eval command not only to displace the variable, but also to execute the corresponding command. The

A scan is performed with variable substitution, and the second scan executes the command contained in the string, cat test.

3. Displays the last parameter passed to the script.

4, give each value a variable name.

Eval "${name}=${value}"



This article is from the "July boreas" blog, please be sure to keep this source http://luminous.blog.51cto.com/10797288/1835910

Profiling related commands in shell scripts

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.