Catch Keypress To Stop A Timer In Bash On Linux

View previous topic View next topic Go down

Catch Keypress To Stop A Timer In Bash On Linux

Post by jamied_uk on 23rd May 2016, 14:24

Code:
#!/bin/bash
# Usage ./test.sh
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi

count=0
keypress=''
while [ "x$keypress" = "x" ]; do
  let count+=1
  echo -ne $count'\r'
  keypress="`cat -v`"
done

if [ -t 0 ]; then stty sane; fi

echo "You pressed '$keypress' after $count loop iterations"
echo "Thanks for using this script."
exit 0

# since=$(date +%s);watch -tn 1 eval "echo \$((\$(date +%s) - $since))"

To make executable
Code:
sudo chmod +x test.sh
avatar
jamied_uk
Admin

Posts : 2280
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum