I initiated a bash script by xbindkeys as

"sleep 1;bash /home/scripts/loop.sh"

How can I bind another key, which can break this bash script?

For example, if loop.sh is 1,000 clicks by pressing KP_Add, how can I break the bash loop after 200 clicks by pressing KP_Substract?

  • 1
    So you would try to interrupt the bash script with human reflexes? Or do you want to set a signal file (or alternative) so that loop.sh knows to stop at 200? Or??? – Jeff Schaller Oct 27 '18 at 20:49
  • @JeffSchaller either way works for me. I can put a condition in the bash script to be interrupted by a key (I don't know how to do so, because it is not in the terminal) OR bind a key in xbindkey to interrupt the running script. By the way, 200 is not a preset value. I just mean interrupting the script whenever needed before the end of the loop. – Googlebot Oct 27 '18 at 21:13

I would suggest binding a key to an action that kills the script:

"pkill -f bash /home/scripts/loop.sh"

The pkill command above uses the -f option to match the given script name against the full process name; any matching process is then killed. I copied the script name directly from the KP_Add example you gave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.