Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Could someone clarify how math functions work?
- X-seq: zsh-users 19584
- From: Eric Cook <llua@xxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Could someone clarify how math functions work?
- Date: Thu, 18 Dec 2014 22:45:20 -0500
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
In the `functions -M' section of zshbuiltins there is the sentence:
"The result of the last arithmetical expression evaluated inside the
shell function (even if it is a form that normally only returns a
status) gives the result of the mathematical function."
but:
zsh -c 'add() ( for arg; do (( n += arg )); done; print n: $n );
functions -M add; print results: $(( add(1,2,3) ))'
Outputs:
n: 6
results: 3
where as:
zsh -c 'add() { local arg n; for arg; do (( n += arg )); done; print n:
$n }; functions -M add; print results: $(( add(1,2,3) ))'
Outputs:
n: 6
results: 6
Is that expected behavior? If so, could you explain why?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author