UNIX & Linux Convert strings to command execution

Source: Internet
Author: User

This article applies to the following topics:

  1. Unix & Linux Convert string to command

  2. UNIX & Linux Convert strings to command execution

  3. How to convert a string into a command in a Linux sh script

Answer:

Use the eval command in a shell script (this command is Bash's built-in command, which is used when Bash's built-in commands view help with man Eval), not exec.

Grammar:

Eval parameters

Parameters can be strings for a set of commands, such as "eval yum install Dstat–y", if you do not add parameters directly to Eval can also, return error code is still 0 (successful execution), but meaningless.

Why not exec?

Because exec exits the current shell script automatically after execution, all rows after exec are ignored.

Why does exec automatically quit?

exec does not start a new shell, but instead replaces the current shell (the currently running script or login session) with the command that follows it.

This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1537282

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.