Skip to main content
4 of 4
format update
Stephen Rauch
  • 4.3k
  • 15
  • 24
  • 33

add script will not return intended output

I want a script to calculate the sum of the numbers entered by the user.

so far I have:

#!/bin/bash
add() {
  sum=0

  for num
  do
          sum=$((sum +num))
  done

}

echo "$sum"

the command I use is:

add 4 -3 9 12

the return is: blank line - not the words just a blank line username~/folder:>

what am I missing?

permissions are rwxr xr x I'm running an interactive shell with the folder in my path, I'm at a loss.