1 |
#!/bin/bash |
2 |
# |
3 |
# Job control constructs: |
4 |
# & terminator (instead of ;) |
5 |
# $! -- last PID |
6 |
# wait builtin (wait -n waits for next) |
7 |
# |
8 |
# Only interactive: |
9 |
# fg |
10 |
# bg |
11 |
# %1 -- current job |
12 |
|
13 |
### Brace group in background |
14 |
{ sleep 0.01; exit 99; } & wait; echo $? |
15 |
# stdout: 0 |
16 |
# status: 0 |
17 |
|
18 |
### Wait on background process PID |
19 |
{ sleep 0.01; exit 99; } & wait $!; echo $? |
20 |
# stdout: 99 |
21 |
# status: 0 |
22 |
|
23 |
### Builtin in background |
24 |
echo async & wait |
25 |
# stdout: async |
26 |
# status: 0 |
27 |
|
28 |
### Async for loop |
29 |
for i in 1 2 3; do |
30 |
echo $i |
31 |
sleep 0.0$i |
32 |
done & wait |
33 |
# stdout-json: "1\n2\n3\n" |
34 |
# status: 0 |