I need to create a while loop that continuously loops until a key press is registered, specifically the 'q' key for quit.
Here's my (failed) attempt:
while [ -z "$QUIT" ]
do
<Script stuff>
done &
read -sn 1 QUIT
export QUIT
However the while loop doesn't exit / end if I press any key. This is because $QUIT seems to only be accessible 'forwards' from where it is set, not backwards to the parent while loop section. Is there a way around this, or an alternative method for allowing my while loop to exit when a key (q if possible) is pressed?
Cheers.