1trap _notify CHLD
2NOTIFY_ALL=false
3unset NOTIFY_LIST
4unalias false
5
6false()
7{
8	return 1
9}
10
11_notify ()
12{
13	local i j
14	local newlist=
15
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 "$@"
24		do
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"
31			fi
32		done
33		NOTIFY_LIST="$newlist"
34	fi
35}
36
37notify ()
38{
39	local i j
40
41	if [ $# -eq 0 ]; then
42		NOTIFY_ALL=:
43		set -b
44		return
45	else
46		for i in "$@"
47		do
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"
54				;;
55			esac
56		done
57	fi
58}
59