The substitution of several basic commands in a shell script under Linux _linux shell

Source: Internet
Author: User

Part 1: ' Command '

This is the "command standard output as a function of standard input" method of operation, there are great drawbacks and unsafe places.

disadvantage one: relatively old.

disadvantage two: easy to confuse with single quotes. (Actually it's your keyboard "!) "That key on the left."

Part 1.5 ' command ' differs from $ (command)

Just look at a few pictures and see how this picture explains their difference ...

You can see two expressions, which are executed directly and nested on behalf of the command.

we find that execution `` $() is the same as it is.

In fact, here is a small bug ... (Orange Box): How do you know that a nested execution computer is really mosaic-executed?

So I have a screenshot ... You can see that the computer is actually doing this from left to right in the case of direct execution.

So to prove that the nesting execution computer is really mosaic execution, we operate is really effective!

They support multi-layer nesting, which has an enormous effect on operation and maintenance.

Part 2: $ (command)

This is the "command standard output as a function of standard input" operation method bis, the use of this method is the most people!

The advantage of this approach is that $(command) Multiple command extensions can be nested in a form.

Part 3: ${command}

What does that mean, exactly? In short, the variable function is $() replaced to \${} output

Well... It means that it's here but it's not right. But we now know two points about ${} the

1th: $() is used to run the command, not to run the replacement variable. In short, it \$() 's used to execute orders.

2nd: ${} is used to replace the variable. But it does not give you the ability to perform variable substitutions, only to help \$() read the information.

3rd: echo ${#name} You can count the replacement variable length units.

Conclusion: $() used to execute; \${}

Part 4: $ () {command}

This is not the case here.

Conclusion: $(){command} Defines a method named \$, which executes the command command

Final text:

` command``$(command) There is no difference between the two, is to execute the command. "Command standard output as function standard input"

\${command} $(){command} similar to those of two. The former is used to read variable replacement content, but cannot be performed.

Well... Add a little words. The group of Friends gave me an official Handbook of RHCE, which has a simple explanation for "command standard output as a function standard input", namely: command substitution.

Command replaces the command itself with the output substitution of the command. Command substitution occurs when the command contains leading dollar signs and parentheses $(command) or inverted quotes command .

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.

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.