bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

TRAP and bash


From: Keith Christian
Subject: TRAP and bash
Date: Mon, 21 May 2001 11:26:20 -0600

The TRAP command in the script below works in sh under Solaris and
HP-UX,
but not under BASH 2.04 (which should be compatible in this area at
least.)

Would anyone hazard a guess (and maybe a correction to the script) why
this
fails under BASH?

Thanks in advance, folks.

=====Keith


#!/bin/sh
#
# From Portable Shell Programming by Bruce Blinn, p 110
#
# Operation: This script will wait for 10 seconds for
# the user to enter data and press return at the prompt.
# If the script times out, the message
# "Out of loop, exiting." is printed.
#
# Sample output below:
#
#
#       ebsdev01  38  /home/kchristi/java>../bourne_read_with_timeout.sh
#
#
#       Mon May 21 10:30:29 MST 2001
#       Waiting for input, press RETURN at the prompt:
#
#
#       Out of loop, exiting.
#       Mon May 21 10:30:39 MST 2001
#
#
# The script does not time out when run under BASH Version 2.04
# It works on current versions of Solaris and HP-UX.
#
######################################################################

trap ":" 2
(sleep 10; kill -2 $$)&
date
echo "Waiting for input, press RETURN at the prompt:\c"
read ANSWER
if kill -0 $! 2>/dev/null; then
        kill $!
fi
case  "$ANSWER" in
        y | yes )    FLAG=TRUE ;;
        * )          FLAG=FALSE ;;
esac
trap 2
echo
echo
echo Nothing was entered within 10 seconds.
echo "*** EOJ ***"
date




_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]