1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-04-28 10:23:23 -07:00
rc/sh/sum
Connor Olding 90038bf996 allow numbers to end with a comma in the sum command
makes it easier to paste stuff into the terminal
2022-03-05 17:41:17 -08:00

26 lines
486 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
for i; do
i="${i%,}"
: $((sum+=i))
done
echo "$sum"
}
[ -n "${preload+-}" ] || sum "$@"