从脚本执行的背景shell命令 [英] executing shell command in background from script
本文介绍了从脚本执行的背景shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能在后台从bash脚本中执行shell命令,如果命令是在一个字符串?
how can I execute a shell command in the background from within a bash script, if the command is in a string?
例如:
#!/bin/bash
cmd="nohup mycommand";
other_cmd="nohup othercommand";
"$cmd &";
"$othercmd &";
这不工作? - 我怎么能做到这一点。
this does not work -- how can I do this?
推荐答案
离开了引号
$cmd &
$othercmd &
例如:
nicholas@nick-win7 /tmp
$ cat test
#!/bin/bash
cmd="ls -la"
$cmd &
nicholas@nick-win7 /tmp
$ ./test
nicholas@nick-win7 /tmp
$ total 6
drwxrwxrwt+ 1 nicholas root 0 2010-09-10 20:44 .
drwxr-xr-x+ 1 nicholas root 4096 2010-09-10 14:40 ..
-rwxrwxrwx 1 nicholas None 35 2010-09-10 20:44 test
-rwxr-xr-x 1 nicholas None 41 2010-09-10 20:43 test~
这篇关于从脚本执行的背景shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文