>_ IzzyLab

Topic breakdown

When a script's behavior depends on the value of a single variable (here, the first argument $1), it's cleaner to use a case construct instead of an if/elif ladder: it compares the value against a set of patterns and runs the branch of the first match. Each branch has the form pattern) commands ;;, and the pattern * at the end catches everything else as the default — a handy place to return a non-zero code for an unknown subcommand. The block opens with the word case and closes with esac.

What's checked

  1. svc start prints starting
  2. svc stop prints stopping
  3. svc status prints running
  4. unknown command gives exit code 2

What it looks like