[ale] Shell Script Question

Michelangelo Grigni mic at mathcs.emory.edu
Wed Apr 14 11:01:15 EDT 1999


> From: Wandered Inn <esoteric at denali.atlnet.com>
> Russell Enderby wrote:
> > At the beginning of the script I currently have:
> > :
> > trap "" 2 3
> > 
> > This currently disables control-c, although I have been unable to find a
> > way to disable control-d.  If anyone has this information that would be
> > great.
> 
> in signal.h ...

I think he means the default stty bindings, where ^D means
end-of-input on the tty (the keyboard).  This means that
the next read() returns 0 bytes.  It is not a signal, and
so "trap" cannot be used to disable it.

However, a program can keep on trying to read, even after
reading 0 bytes.  Here is a ksh version of "tail -f", it
keeps echoing lines even after the user types ^D:

#!/bin/ksh -p
# A ksh approximation to "tail -f"
while :
do
  if read line
  then echo "$line"
  else sleep 1
  fi
done






More information about the Ale mailing list