>_ IzzyLab

Topic breakdown

When the number of arguments isn't known in advance, accessing $1, $2 one at a time is pointless — the whole list is handed over by the special variable "$@", which is convenient to iterate over with a loop. The classic summing technique is an accumulator variable to which the current element is added on each iteration; integer arithmetic in bash is provided by the $(( ... )) construct, and inside it variable names are written without $. The script is placed in a directory from $PATH (/usr/local/bin) and made executable so it can be called by name.

What's checked

  1. sumargs is executable
  2. sumargs 3 4 5 gives 12
  3. sumargs with a single argument gives the number

What it looks like