Patch-ID: bash40-021
[bash.git] / examples / functions / notify.bash
blobdafbac5a8f9edd9097d37b5e393f009a65b459f5
1 trap _notify CHLD
2 NOTIFY_ALL=false
3 unset NOTIFY_LIST
4 unalias false
6 false()
8 return 1
11 _notify ()
13 local i j
14 local newlist=
16 if $NOTIFY_ALL
17 then
18 return # let bash take care of this itself
19 elif [ -z "$NOTIFY_LIST" ]; then
20 return
21 else
22 set -- $NOTIFY_LIST
23 for i in "$@"
25 j=$(jobs -n %$i)
26 if [ -n "$j" ]; then
27 echo "$j"
28 jobs -n %$i >/dev/null
29 else
30 newlist="newlist $i"
32 done
33 NOTIFY_LIST="$newlist"
37 notify ()
39 local i j
41 if [ $# -eq 0 ]; then
42 NOTIFY_ALL=:
43 set -b
44 return
45 else
46 for i in "$@"
48 # turn a valid job spec into a job number
49 j=$(jobs $i)
50 case "$j" in
51 [*) j=${j%%]*}
52 j=${j#[}
53 NOTIFY_LIST="$NOTIFY_LIST $j"
55 esac
56 done