mirror of
https://github.com/notwa/rc
synced 2024-11-05 06:39:02 -08:00
23 lines
462 B
Bash
23 lines
462 B
Bash
#!/usr/bin/env sh
|
|
# YES_ZSH
|
|
# YES_BASH
|
|
# YES_DASH
|
|
|
|
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
|
|
: $((sum+=i))
|
|
done
|
|
echo "$sum"
|
|
}
|
|
|
|
[ "${SOURCING:-0}" -gt 0 ] || sum "$@"
|