while true
do
echo "Enter the number"
read Num
while[$Num -lt 1 || $Num -gt 50]
do
echo "Please enter a new number "
read Num
done
Asked
Active
Viewed 513 times
-1
Michael Homer
- 76,565
1 Answers
3
There are some errors and warnings. Also please use shellcheck.net in these kind of situations.
Errors:
Space between
whileand[.Space after
[and before].Disaster because there is no
done, may be you forgot or you just pasted half of your code.Use
[ a ] || [ b ]instead of[ a || b ].
Warnings:
You should use
read -rinstead ofread.Double quote variable names otherwise this will not work if they have special characters.
Correct Code:
while true
do
echo "Enter the number"
read -r Num
while [ "$Num" -lt 1 ] || [ "$Num" -gt 50 ]
do
echo "Please enter a new number "
read -r Num
done
done
ilkkachu
- 138,973
Prvt_Yadav
- 5,882
done? – Prvt_Yadav Mar 15 '19 at 03:23whileand[. There are tons of shell script examples online. – Peschke Mar 15 '19 at 03:27[and$Numand50and]. – Nasir Riley Mar 15 '19 at 03:27while[, or the wholewhile[...], or an error about the glob not matching, so the error message in the title and the code in the script don't even match. – ilkkachu Mar 15 '19 at 12:10