Bash: Check if enter was pressed

intelinside picture intelinside · Apr 30, 2012 · Viewed 7.3k times · Source

How can I check in Bash if the Enter key has been pressed? I'm using the read command:

read -p "Please press ENTER" var

Answer

Bruno picture Bruno · Apr 30, 2012

Firstly, check whether the exit status is normal ($? should be 0).

Secondly, check that $var equals "".