I am looking for a conditional to avoid users from leaving an input value blank. Any suggestions?
2 Answers
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
-
2This has the (minor) problem of not handling ^D as end-of-input, so it will loop forever if it reads from
/dev/null
. That can be dealt with if you write it aswhile read input && [ -z "$input" ]; do :; done
.– IdelicCommented Nov 7, 2011 at 7:01 -