I don't know why, but only the '0' option works, unless the 'clear' command is removed or commented out. See the script:
NUMERO=-1
while [ $NUMERO -ne 0 ]; do
clear
echo "------ M E N U ------"
echo "1 - Primeira opção"
echo "2 - Segunda opção"
echo "3 - Terceira opção"
echo "0 - Sair"
while true; do
read -p "Opção: " NUMERO
[[ -n "$NUMERO" ]] && break
done
if [ $NUMERO == 1 ]; then
echo "Você escolheu a opção $NUMERO"
elif [ $NUMERO == 2 ]; then
echo "Você escolheu a opção $NUMERO"
else
echo "Você escolheu a opção $NUMERO"
fi
done
After adding 'exec 3>trace.log; BASH_XTRACEFD=3; set -x' to the beginning of the script, I got the following content in the trace.log file:
+ NUMERO=-1
+ '[' -1 -ne 0 ']'
+ clear
+ echo '------ M E N U ------'
+ echo '1 - Primeira opção'
+ echo '2 - Segunda opção'
+ echo '3 - Terceira opção'
+ echo '0 - Sair'
+ true
+ read -p 'Opção: ' NUMERO
+ [[ -n 1 ]]
+ break
+ '[' 1 == 1 ']'
+ echo 'Você escolheu a opção 1'
+ '[' 1 -ne 0 ']'
+ clear
+ echo '------ M E N U ------'
+ echo '1 - Primeira opção'
+ echo '2 - Segunda opção'
+ echo '3 - Terceira opção'
+ echo '0 - Sair'
+ true
+ read -p 'Opção: ' NUMERO
+ [[ -n 0 ]]
+ break
+ '[' 0 == 1 ']'
+ '[' 0 == 2 ']'
+ echo 'Você escolheu a opção 0'
+ '[' 0 -ne 0 ']'


exec 3>trace.log; BASH_XTRACEFD=3; set -xto the top of your script, then edit the contents oftrace.loginto the question. (Make sure you're actually running it with bash, not sh, and that the bash version is 4.3 or later for that logging to work).clearwould have anything to do with triggering them.==isn't a POSIX-standardized string comparison operator -- only=is guaranteed to work on shells that implement only bare-minimum POSIX functionality. And make sure you compare"$NUMERO"not$NUMERO. Additionally, consider making a habit of using lowercase names for your own variables -- all-caps names are used by names meaningful to the shell and OS-provided tools, so by using lowercase names you ensure that you aren't changing other components' behavior by mistake.clearcan modify$?and thus modify control flow, but that's not the case in the specific script you show here. You've got some kind of a side effect going on -- maybe something wrong with your terminal where the control sequences are influencing following input? -- but we can't diagnose it without further details.sleep 1at the end of the loop so there's a delay before it goes back to the top?selectcommand.