It turns out the problem was that my cleanup function called stty , and stty apparently doesn't like to be called, and stdin redirected from the file. Thus, when I pressed Ctrl-C while the script was executing the read loop, the cleanup function was called as if I had called it from the loop:
while read -r line; do ... cleanup ... done < "$filename"
This, in turn, meant that stty was executed with a redirected stdin , and he died with the error stty: standard input: Inappropriate ioctl for device .
I was able to fix this by changing the trap line:
trap "break" SIGINT SIGHUP SIGTERM
Therefore, instead of effectively inserting a cleanup call into my loop when I press Ctrl-C, instead it simply (efficiently) inserts a break into the loop, thereby breaking out of the loop and then calling cleanup through the line after the loop.
Mike holt
source share