[Scottish] Trapping SIGINTR in shell scripts

Martin McCarthy marty at ancient-scotland.co.uk
Wed Aug 25 11:09:00 BST 2004


> I've got a "run-parts" shell script that runs all executables in a directory
> that I use.
> 
> -- snip active bit--
> for i in $1/* ; do
>         [ -d $i ] && continue
>         if [ -x $i ]; then
>                 $i
>         fi
> done
> -- end section --
> 
> However what I want to happen is if I press ctrl-c (SIGINTR 2)
> that my "run-parts" script doesn't stop, but the presently running script
> below stops.
> 
> do I simply get my run-parts script to ignore ctrl-c
> (ie trap "" 2)
> 
> or is it more complicated than this...

You'll probably want to untrap the ^C for the child script.  Something
like:

trap '' 2
for i in "$1"/* ; do
        [ -d "$i" ] && continue
        if [ -x "$i" ]; then
                ( trap 2; "$i" )
        fi
done

Hope that helps,
Martin
-- 
Martin McCarthy                 /</           http://www.theasis.co.uk
marty at ancient-scotland.co.uk    \>\  http://www.ancient-scotland.co.uk
                                /</         http://www.non-prophet.org



More information about the Scottish mailing list