Shell Script (Bash) to sum multiples of different arguments below a number
Arithmetic operations

If you look closely, something is a bit odd here:


for (( i = 0; i &lt;= $limit; i+=$1 )); do



Ideas? How about: i is written without a dollar, but limit is written with a dollar... In fact you can drop the dollar from limit too, and the expression will be slightly simpler. From $1 you cannot drop it, as the meaning of 1 would be taken literally, because it's numeric, unlike the others.

The same is true for commonMultiple here, you can drop the dollar:


for (( i = 0; i &lt;= $limit; i+=$commonMultiple )); do



The general rule is, in arithmetic operations within ((...)) you don't need to use the dollars in variable names.

Don't use backticks

Instead of this:


commonMultiple=`expr $1 \* $2`



This is the recommended writing style for sub shells:

commonMultiple=$(expr $1 \* $2)


Don't use expr

It's better to avoid expr, and you can do the same thing easier using Bash arithmetics, for example:

((commonMultiple = $1 * $2))


The for loops can be simplified similarly, instead of:

for (( i = 0; i &lt;= $limit; i+=$1 )); do
    sumArg1=`expr $sumArg1 + $i`
done


You can write:

for (( i = 0; i &lt;= limit; i+=$1 )); do
    ((sumArg1 += i))
done


Apply the same thing everywhere.