Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

UNIX & Linux converts strings into command execution

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report