我写了一个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命令后控制到下一条语句
发布评论