I am trying to write a Bash script that takes a list of numbers as command line arguments and then outputs the sum of those numbers.
So the script would be run as
script.sh 1 555 22 122 66 and would then sum them all up. I know they need to be passed to the
$@ variable and then likely run through a loop, but I don't understand how to convert the contents of
$@ to an int to do the math. I tried to do this:
#!/bin/bash for i in $@ do $@+$@ echo "the total is `$@`" done