checking a variable is within range

how can i check that a variable is between 0-100, like if i ask a user to input a number between 1-100 and i want to excute commands WHILE that number is between that range or else i will keep asking the user to make another input

here's what i got

#!/bin/bash
echo "Guess my secret number (0-100): "
number=$((RANDOM%100+0))
echo "$number"
read GUESS

I've tried all sorts of things but I keep getting errors, i tried:

if echo $GUESS | grep "^[0-9]*$">aux
then
  echo "good"
else
  echo "bad"
fi
rm aux

and i've tried

if [ -n "$( print - "$GUESS"           |\
            sed 's/^[+-]//;s/[0-9]//g;s/\.//'   \
          )" ] ; then
     echo "good"
else
     echo "bad"
fi

i'm always getting errors like command not found and unexpected end of file, can anyone pls help me?

This will validate a number between 0 and 100 both inclusive.

[/tmp]$ cat try.sh
#! /bin/sh

echo "Guess my secret number (0-100): "
read GUESS

if [[ $GUESS -ge 0 && $GUESS -le 100 ]] ; then 
  echo "good"
else
  echo "bad"
fi

Thanks :slight_smile: