Take this script
#!/bin/sh
fd ()
{
echo Hello world
exit
}
trap fd EXIT INT
for g in {1..5}
do
echo foo
sleep 1
done
I would like fd
to fire once, either from Control-C or if the script exits normally. However if you hit Control-C it will run twice. How can I fix this?