| 1 | #!/usr/bin/env bash
 | 
| 2 | 
 | 
| 3 | # This causes an segfault in bash and dash!  I think it's an infinite loop.
 | 
| 4 | # zsh hangs
 | 
| 5 | # trap term TERM
 | 
| 6 | 
 | 
| 7 | term() {
 | 
| 8 |   kill 0  # terminates the current process group
 | 
| 9 | }
 | 
| 10 | 
 | 
| 11 | main() {
 | 
| 12 |   local background=${1:-}
 | 
| 13 | 
 | 
| 14 |   if test -n "$background"; then
 | 
| 15 |     # shouldn't wait for this to finish!
 | 
| 16 |     sleep 3 &
 | 
| 17 |   fi
 | 
| 18 | 
 | 
| 19 |   if false; then
 | 
| 20 |     {
 | 
| 21 |       while true; do
 | 
| 22 |         echo ___
 | 
| 23 |         sleep 0.2
 | 
| 24 |       done 
 | 
| 25 |     } &
 | 
| 26 |   fi
 | 
| 27 | 
 | 
| 28 |   echo 'MAIN'
 | 
| 29 |   echo foo | grep foo
 | 
| 30 |   sleep 0.2
 | 
| 31 |   echo 'DONE'
 | 
| 32 | 
 | 
| 33 |   term
 | 
| 34 | }
 | 
| 35 | 
 | 
| 36 | trace() {
 | 
| 37 |   bin/osh -O oil:basic -x $0 main "$@"
 | 
| 38 | }
 | 
| 39 | 
 | 
| 40 | "$@"
 |