Command substitution and eval commands under the shell

Source: Internet
Author: User

In the shell, if you want to get the return value of a command, if it is an integer, you can get its exit code directly with $.

But if the return value of a command is not an integer, how is it implemented?

Have to mention the command substitution function under the shell!

Two ways of implementing command substitution

Assuming that we need to get the current time for a variable, we can do this:

Date= ' Date '

Echo $date

Or you can do it.

date=$ (date)

Echo $date

Both of these methods can implement the function of command substitution, so how are they different?

The difference between two kinds of command substitution methods

1.$ () looks relatively concise, and ' easily confused ' with '.

2. In multi-layer replacement ' need to be escaped, more trouble

3. "More portability because $ () does not guarantee that all Linux systems can support

eval command

The eval command is used to tell the shell to take out the eval parameters and re-compute the parameter contents.

Like what:

Val=123

Cmd= "Echo $val 456789"

echo $cmd #echo 123 456789

Eval $cmd #123 456789

Command substitution and eval commands under the shell

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.