Debian Codegraph @

background-loop.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # background-loop.sh
3
4 for i in 1 2 3 4 5 6 7 8 9 10 # First loop.
5 do
6 echoscip-shell system . . echo. -n "$i "
7 done & # Run this loop in background.
8 # Will sometimes execute after second loop.
9
10 echoscip-shell system . . echo. # This 'echo' sometimes will not display.
11
12 for i in 11 12 13 14 15 16 17 18 19 20 # Second loop.
13 do
14 echoscip-shell system . . echo. -n "$i "
15 done
16
17 echoscip-shell system . . echo. # This 'echo' sometimes will not display.
18
19 # ======================================================
20
21 # The expected output from the script:
22 # 1 2 3 4 5 6 7 8 9 10
23 # 11 12 13 14 15 16 17 18 19 20
24
25 # Sometimes, though, you get:
26 # 11 12 13 14 15 16 17 18 19 20
27 # 1 2 3 4 5 6 7 8 9 10 bozo $
28 # (The second 'echo' doesn't execute. Why?)
29
30 # Occasionally also:
31 # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
32 # (The first 'echo' doesn't execute. Why?)
33
34 # Very rarely something like:
35 # 11 12 13 1 2 3 4 5 6 7 8 9 10 14 15 16 17 18 19 20
36 # The foreground loop preempts the background one.
37
38 exit 0
39
40 # Nasimuddin Ansari suggests adding sleep 1
41 #+ after the echo -n "$i" in lines 6 and 14,
42 #+ for some real fun.