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

Re: new user questions and issues



Most of this has been answered already, throwing one extra remark.

On May 6, 10:37am, Kannan Varadhan wrote:
}
} Issue #2.  Overridden local variables get echoed?

The tidbit that no one has explicitly mentioned is that "local" et al.
has function scope, so it makes no sense to declare something "local"
inside a loop body.  (In an if/else, it could make sense, as long as
the if/else is not itself inside a loop, but the variables declared
there will persist beyond the "fi".)

If you for some reason need a declaration to be local to a loop, use
an anonymous function context like this:

    local _t2
    for _t2 in 0 1 2 ; do
      function {
        local _t3
        _t3=XXX__${_t2}__
      }
    done



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