Here’s a script I worked out at a Hackathon last weekend to listen for input in BASH without maxing your CPU.
#Listens for input on ttyACM0 (an arduino button) nd #output the string to a file. Note this file must #already exist and I highly recommend making a ram #disk for it. It also backgrounds the listening cat /dev/ttyACM0 >> /tmp/input & #I had to sleep my script for 5 seconds to get #rid of a false trigger. You can probably delete this sleep 5 #Clears out the file echo -n "" > /tmp/input while true; do if [ -s /tmp/input ]; then #If temp > 0b #do stuff! echo -n "" > /tmp/input #Clears the input fi sleep 1 #This sleep is important! it controls #The while loop. done