N
N
nihi1ist2021-07-17 07:27:06
bash
nihi1ist, 2021-07-17 07:27:06

How to prevent null input in bash command line option?

Tell me how to prohibit the input of an empty value when requested, for example, through the same read? So that when entering an empty value, the user is prompted to enter a value or to abort the script?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2021-07-17
@nihi1ist

well just check like this

while true; do
read -p "Enter value: " MYVAR
 && break
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question