mirror of
https://github.com/notwa/rc
synced 2024-07-01 03:07:13 -07:00
document sum
This commit is contained in:
parent
687f9adfa8
commit
0b05eaa4b5
9
sh/sum
9
sh/sum
|
@ -4,6 +4,15 @@
|
||||||
# YES_DASH
|
# YES_DASH
|
||||||
|
|
||||||
sum() { ### @-
|
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
|
local sum=0
|
||||||
for i; do
|
for i; do
|
||||||
: $((sum+=i))
|
: $((sum+=i))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user