-1
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
Michael Homer
  • 76,565

1 Answers1

3

There are some errors and warnings. Also please use shellcheck.net in these kind of situations.

Errors:

  1. Space between while and [.

  2. Space after [ and before ].

  3. Disaster because there is no done, may be you forgot or you just pasted half of your code.

  4. Use [ a ] || [ b ] instead of [ a || b ].

Warnings:

  1. You should use read -r instead of read.

  2. 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