I know this question has been already asked & answered, but the solution I found listens for space and enter:
while [ "$key" != '' ]; do read -n1 -s -r key done Is there a way (in bash) to make a script that will wait only for the space bar?
I know this question has been already asked & answered, but the solution I found listens for space and enter:
while [ "$key" != '' ]; do read -n1 -s -r key done Is there a way (in bash) to make a script that will wait only for the space bar?
I suggest to use only read -d ' ' key.
-d delim: continue until the first character of DELIM is read, rather than newline
See: help read
-s flag, like read -s -d ' ' (you don't need the key variable here, if you only want it to wait for the space key) read is painfully inefficient: it makes a system call for each character it reads (which is kind of why it can do this trick of reading a space without needing Enter). For more reasons to avoid using read unless you have no other option, please see Stéphane's excellent answer here: unix.stackexchange.com/q/169716/88378