Get the App
SLTechnology News&Howtos  ›  Servers  › 

UNIX & Linux converts strings into command execution

Shulou Source: shulou.com Published: 2022-06-02 13:24:17 10月15日 Update

This article applies to the following topics:

Unix & Linux convert string to command

UNIX & Linux converts strings into command execution

How to convert a string to a command in Linux sh script

Answer:

Use the eval command in your shell script (this command is a built-in command for bash, and man eval is used for all bash built-in commands to view help) instead of exec.

Syntax:

Eval parameter

Parameters can be strings of a set of commands, such as "eval yum install dstat-y". If you execute eval directly without arguments, the error code is still 0 (successful execution), but it doesn't make sense.

Why not use exec?

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

Why did exec quit automatically?

Instead of starting a new shell, exec replaces the current shell (the currently running script or login session) process with the following commands.

Tags: Commands scripts characters strings parameters orders success no topics code meaning answers but syntax processes errors help login run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi MySQL vpn Huawei