Answer the question
In order to leave comments, you need to log in
How to simplify a Bash construct without using if then else!?
Depending on the Y or N key pressed, the Variable variable takes the value TRUE (y) or FALSE (n)...
Is it possible to describe this construction in a simpler way:
read -r -n1 -p "Ask some question. y/n " key
if [${key^^}=="Y"]; then
variable=true
else
variable=false
fi
Answer the question
In order to leave comments, you need to log in
You can remove else
read -r -n1 -p "Ask some question. y/n " key
variable=false
if [ ${key^^} == "Y" ]; then
variable=true
fi
read -r -n1 -p "Ask some question. y/n:" key
[ ${key^^} = 'Y' ] && variable=true || variable=false
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question