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

Re: unexpected unmodified variable



On Thu, Oct 6, 2022 at 6:37 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Playing with that, it seems the last math operation gets to be the rv
> unless you set a return value

Yes, that's documented.  Interpreting the argument of "return" counts
as a math operation, so the math value of a "functions -M" function
really is always the last math operation.

> ... I had : "return 3" active, but commenting it out didn't seem to
> change anything which is puzzling.

I think you must have typo'd something somewhere.  Add "functions -t
func2" so you can see a trace of what's executing.

>  Anyway, it seems that 'count' can be
> a normal variable just so long as 'func2' is called mathematically.

That's not exactly the point ... what kind of variable "count" is, in
this case, doesn't matter.  What matters is that $(( func2() )) runs
in the current shell, not in a subshell.

In case it wasn't obvious, $(( func2 )) treats func2 as the name of a
variable, not a function, so it doesn't run func2 at all.




Messages sorted by: Reverse Date, Date, Thread, Author