Simple bash problem.

Miskell, Craig Craig.Miskell at agresearch.co.nz
Mon Jan 29 00:07:05 UTC 2007


> Anyone know why the following simple bash script fails
> on RHEL3 (fully patched)?  It seems the "trap" command
> is being silently ignored.
> 
> 
> --------------------------------------------
> #!/bin/sh
> 
> sigtrap () {
>     echo "Caught signal!"
>     exit 0
> }
> 
> trap sigtrap 1 2 3 15
> 
> while read X; do
>     echo $X
> done
> --------------------------------------------

I'm not 100% sure, but I think it might be because of the #! Line.  Bash
might be seeing that you've invoked with "/bin/sh", and is deciding to
operate in limited POSIX shell mode (sorry, the exact terminology for
that escapes me).  Try #!/bin/bash and see how that goes,

Craig
=======================================================================
Attention: The information contained in this message and/or attachments
from AgResearch Limited is intended only for the persons or entities
to which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipients is prohibited by AgResearch
Limited. If you have received this message in error, please notify the
sender immediately.
=======================================================================




More information about the redhat-list mailing list