>_ IzzyLab

Topic breakdown

Checking a string against a pattern in bash is conveniently done with the case operator, which matches a value against glob patterns (this is not regex — it's its own syntax). Inside a [...] class, a ! at the start means negation, and * on the edges means "anything around", so you can build a pattern that catches the presence of an "unsuitable" character. It's often more reliable to catch precisely the negative cases (including an empty argument) in separate branches and leave the "good" case to the default branch; the answer is given via the exit code.

What's checked

  1. isnum is executable
  2. isnum 12345 returns 0
  3. isnum 12a45 returns 1

What it looks like