Questions about rewriting the History function.

Bill Shannon shannon at datsun.Sun.COM
Sun Oct 28 11:28:25 AEST 1990


Several people suggested:

>   You can get asynch job notification in ksh88 by doing:
> 
> 	trap "jobs -n" CHLD

This is almost, but not quite, good enough for what I want.  I want
to be able to emulate both the csh "set notify" command and the csh
"notify" command.  The above emulates only the "set notify" command.
Here's a message I set to Korn on this subject some time ago:

>From shannon Sat May 27 02:24:58 1989
To: dgk at ulysses.att.com
Subject: traps

I'm playing around with trapping SIGCHLD to emulate the csh notify
command.  the following code in io_intr() causes a newline to be
printed every time you execute the trap handler, even if it produces
no other output.

		if(sh.trapnote&TRAPSET)
		{
			newline();
			fp = st.standin;
			sh_chktrap();
			io_clear(fp);
			return(0);
		}

for example, do

	trap true CHLD
	sleep 5 &

there might be cases where the newline is helpful, but in this
case it makes it impossible for me to do what I want to do.
(that coupled with the fact that functions can't effect the traps
of the mainline shell.  otherwise I could set and unset the trap
when necessary and that might be good enough.)

how do you feel about removing that call to newline(), or at least
making it conditional on something so it won't happen when catching
SIGCHLD?


FYI, here's as far as I've gotten with my notify emulation.  this
works pretty well, but I think there's other problems in the shell
that prevent it from working perfectly.  for instance, if I do

	sleep 5 & sleep 5 & notify %1 %2

sometimes it tells me about both jobs and sometimes it loses one of
the jobs.  any ideas what else could be wrong?


trap _notify CHLD
NOTIFY_ALL=false
unset NOTIFY_LIST

_notify()
{
	typeset i j

	if $NOTIFY_ALL
	then
		jobs -n
	else
		for i in ${NOTIFY_LIST[*]}
		do
			j=`jobs -n %$i`
			if [ "$j" ]
			then
				echo "$j"
				unset NOTIFY_LIST[$i]
			fi
		done
	fi
}

notify()
{
	typeset i j

	if (($# == 0))
	then
		NOTIFY_ALL=true
	else
		for i in "$@"
		do
			# turn any valid job specification into a job number
			j=`jobs "$i"`
			case "$j" in
			\[*)
				j=${j%% *}
				j=${j%\]}
				j=${j#\[}
				NOTIFY_LIST[$j]=$j
				;;
			esac
		done
	fi
}

unnotify()
{
	if (($# == 0))
	then
		NOTIFY_ALL=false
	else
		# XXX - not done yet
		:
	fi
}



More information about the Comp.unix.shell mailing list