title: How can I get a Bash shell script to listen for a keypress while running, rather than pause and wait for it?
body: <p>I see a post for Powershell but am asking for the Bash shell instead:</p>
  <p>I have a bash script that I want to stop with a simple keypress. It works great with this code:</p>
  <pre><code>read -rsn1 input
  if [ &quot;$input&quot; = &quot;Z&quot; ]; then
      ps -aux | grep program.sh
      killall program.sh
  fi
  </code></pre>
  <p>Except, instead of running, it waits there at this point for the &quot;Z&quot; and nothing happens. Only when I press a different character will it launch, then it works fine.</p>
  <p>What I want is for the program to go and keep going, running UNTIL that &quot;Z&quot; is pressed, and for that to be heard even if window focus is on a different window than the terminal the program is running in. Is that feasible?</p>
  <p>(Also, this program uses Xdotool, does anyone know if that will count if the &quot;Z&quot; is within an Xdotool script? For example, if I have Xdotool type &quot;I'm Going to the Zoo&quot; will that Z be seen as the same as if I'd typed it in the keyboard? I know this is a different issue but I may want to make the key something like Esc instead if that's the case...but it works great for the &quot;Z&quot; right now aside from the issue I'm describing.)</p>
  <p>Thank you!</p>