运行eval命令后控制到下一条语句 [英] control to the next statement after running eval command

查看:52
本文介绍了运行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命令后控制到下一条语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆