mirror of
https://github.com/notwa/rc
synced 2024-11-13 19:59:02 -08:00
22 lines
519 B
Bash
Executable file
22 lines
519 B
Bash
Executable file
#!/usr/bin/env sh
|
|
# compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh
|
|
|
|
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 "$@"
|