title: How to test if variable is a number with certain max digits in linux non-bash shell script
body: <p><a href="https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash#3951175">Here</a> I found nice solution to test if variable is a number:</p>
  
  <pre><code>case $string in
     ''|*[!0-9]*) echo bad ;;
     *) echo good ;;
  esac
  </code></pre>
  
  <p>I'm trying to modify it to test if variable is a 1,2,3 or 4-digit natural number (within a range 0-9999), so I added <code>|*[0-9]{5,}*</code> to exclude numbers with more than 5 digits, but the code below prints <code>good</code> for numbers greater then 9999 e.g. 1234567.</p>
  
  <pre><code>case $string in
     ''|*[!0-9]*|*[0-9]{5,}*) echo bad ;;
     *) echo good ;;
  esac
  </code></pre>
  
  <p>I'm using ash from busybox.</p>