I want to check if the value entered by the user using the read
command is the Enter key using if/elif
statements in order to echo
something. How should I do?
The \n
at the end of the user's input is stripped off before assigning the value to the shell variable. If the user just presses ENTER
, the value read will be the empty string.
read VAR
if [[ -z $VAR ]]; then echo "User pressed ENTER with no input text"; fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With