S
S
SOTVM2018-12-04 16:36:09
bash
SOTVM, 2018-12-04 16:36:09

How to exit the script on Esc?

We have a script that rotates the display of random pictures and quotes in a cycle with an interval of 5 seconds.
How to end it with a single button press, without taking up an extra HOTKEY under the killall script, (preferably by Esc )
you need something a la an event handler in JS, i.e. if the script works and the treasured button was pressed, then we kill
5c0681c482701447931727.gif

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
enabl3, 2018-12-12
@enabl3

I do this to myself, this is what is spinning in the cycle, and by pressing any button, the process is interrupted.

if read -r -n 1 -t 5 -p ""; then
    echo "Process was cancel"
    break
fi

A
Ainur Valiev, 2018-12-08
@vaajnur

Something like
while true; do
read input
if ["$input" = "a"]; then
echo "hello world"
fi
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question