I want to know if there is any way to make my script stop until the user hits the Enter key, but without using the command read
, just by the options of stty
.
I was wondering a code for this and got some search; so I found a code that needs "space" to continue and changed the variable hold
from empty space to \n
, but no success.
That's how it looks like:
function _enter-to-continue() {
local hold='\n' # this solution i tried, but without success
printf "Press 'ENTER' to continue or 'ESC' to cancel... "
local original_tty_state=$(stty -g)
trap "stty $original_tty_state; exit 0" 2
stty intr \033
stty raw isig noflsh echo icrnl
until [ -z "${hold#$in}" ]; do
in=$(dd bs=1 count=1 </dev/tty 2>/dev/null)
done
stty "$original_tty_state"
}
read
? Also, what shell are you writing for,bash
? A literal newline inbash
could be written$'\n'
.