1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-12 15:49:03 -08:00
rc/sh/sum
Connor Olding d5f3f14d72 merge compatibility lines
RIP meaningful last-modified dates
2024-03-26 15:08:14 -07:00

22 lines
483 B
Bash
Executable file

#!/usr/bin/env sh
# YES_ZSH YES_BASH YES_DASH YES_ASH
sum() { ### @-
### compute the summation of its arguments without forking processes.
### this relies on the shell's built-in arithmetic operators.
###
### ```
### $ sum 1 2 3
### 6
### ```
###
### **TODO:** consider renaming because sum(1) already exists.
local sum=0 i=
for i; do
i="${i%,}"
: $((sum+=i))
done
echo "$sum"
}
[ -n "${preload+-}" ] || sum "$@"