bash - Press any key with timeout progress displayed in shell -
i want provide user prompt press key or wait timeout continue using shell. case solved following idiom:
read -rs -t3 -n1 "press key or wait continue ..."
however prompt seems little bit clumsy me , left "press key continue ..." part of message , indicate timeout dots printed each second. write following script:
#!/bin/sh echo -n "press key continue"; _ in `seq 3`; if ! read -rs -n1 -t1 ; echo -n "."; else break; fi done echo
it works expect, there code, have put in separate file instead of using sh -c "..."
in script. there way implement in more concise , compact way?
p.s. returning non-zero error code on ctrl-c
pressed must.
a bit more concise :
echo -n "press key continue"; _ in {1..3}; read -rs -n1 -t1 || printf ".";done;echo
Comments
Post a Comment