I'm running the following script where the glob in the for loop expands to a very large set of files. For some reason the exit due to key press refuses to take... the script prints "detected keypress, exiting" but just keeps going.
I suspect there are subshells being spawned somehow which are sucking up the exit calls but I'm stumped as to how to fix it. The script simply doesn't exit.
#!/bin/sh -e
bindir=`dirname $0`
shopt -s nullglob
dir="$1"
diecygwin=
for complete in "${dir}"/*#complete; do
if [ ! -z "$diecygwin" ]; then
exit "$diecygwin"
continue
fi
seq=${complete//#complete/}
echo -n "${seq} ... "
rc=0
$bindir/other.sh -d "$seq" || rc=$?
if [ $rc -eq 0 ]; then
echo ok
read -t 0.5 -n 1 -s holder && key="$holder"
if [ ! -z "$key" ]; then
echo detected keypress, exiting
exit 0
diecygwin=0
fi
elif [ $rc -ne 100 ]; then
echo fatal error $rc
exit 1
diecygwin=1
fi
done