运行eval命令后控制到下一条语句

编程入门 行业动态 更新时间:2024-10-15 14:17:04
本文介绍了运行eval命令后控制到下一条语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写了一个bash脚本来在后台运行服务,然后从脚本退出并返回命令行.但是,在运行eval命令后,控制权不会继续执行下一条语句.

I have written a bash script to run a service in background and exit from the script to command line. But after running the eval command, control does not go the next statement.

COMMAND="nohup java -jar jenkins.war" echo "starting service" eval $COMMAND echo "service running" exit

回显服务正在运行"并永远不会退出.我想在后台运行该进程,并在服务仍在运行时返回到命令提示符.我该怎么做?

echo "service running" and exit never happens. I want to run the process in the background, and return to the command prompt while the service is still running. How do I do this?

推荐答案

请不要将带有其参数的命令放在 string 中.将命令及其参数放在 array 中(不要使用大写的变量名,这是非常糟糕的做法),并且请勿使用 eval . eval 是邪恶的!

Please, don't put a command with its arguments in a string. Put your command and its arguments in an array (and don't use upper-case variable names, that's a terribly bad practice), and do not use eval. eval is evil!

command=( nohup java -jar jenkins.war ) echo "starting service" "${command[@]}" 2> /dev/null & echo "service running"

& 将使该命令在后台运行.

The & is to have the command running in background.

更多推荐

运行eval命令后控制到下一条语句

本文发布于:2023-11-12 19:52:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582378.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   命令   下一条   eval

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!