Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Could someone clarify how math functions work?



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