• Uncategorized

About bash : How-to-check-for-no-input-in-bash-read

Question Detail

I am looking for a conditional to avoid users from leaving an input value blank. Any suggestions?

Question Answer

No inputs (or even spaces I believe) get entered as empty strings, so check input while the input var is empty:

input=
while [[ $input = "" ]]; do
   read input
done

unset input
while [ -z ${input} ]; do
     read input
done

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.