Linux 运行 shell 命令,不要等待返回
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20670911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:40:34 来源:igfitidea点击:
Run shell command and don't wait for return
提问by Nimjox
Is it possible to start the execution of a command and not wait for it to return before continuing.
是否可以开始执行命令而不等待它返回才继续。
I.E.
IE
commands
/usr/sbin/thing.sh <-- Don't wait for this to return.
more commands
采纳答案by worc
A single &
symbol between commands will let each run independently without relying on the previous command having succeeded.
&
命令之间的单个符号将使每个命令独立运行,而不依赖于前一个命令是否成功。
回答by phyrrus9
hydrogen:tmp phyrrus9$ cat shell.sh
#! /bin/sh
echo hello
sleep 15 &
echo world
hydrogen:tmp phyrrus9$ ./shell.sh
hello
world
hydrogen:tmp phyrrus9$ ps -a
PID TTY TIME CMD
12158 ttys000 0:00.92 login -pf phyrrus9
12159 ttys000 0:00.22 -bash
12611 ttys000 0:00.00 sleep 15
12612 ttys000 0:00.01 ps -a
Append the & to the end of the command. Tested on:
将 & 附加到命令的末尾。测试:
Darwin hydrogen.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64