Run shell command and don't wait for return [d

2019-02-21 12:00发布

Is it possible to start the execution of a command and not wait for it to return before continuing.

I.E.

commands
/usr/sbin/thing.sh    <-- Don't wait for this to return.
more commands

标签: linux bash shell
2条回答
女痞
2楼-- · 2019-02-21 12:17
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
查看更多
劫难
3楼-- · 2019-02-21 12:31

A single & symbol between commands will let each run independently without relying on the previous command having succeeded.

查看更多
登录 后发表回答