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

Re: How to have function local variable but must behave just a simple one



On Sat, 26 Aug 2023 at 10:26, Budi <budikusasi@xxxxxxxxx> wrote:
How to have function local variable but must behave just a simple /
plain variable which is retaining its value all the time, no matter
how many times exit and enter the function

Sort of like a function-scoped static variable in C?

    int counter() {
      static int n = 0;
      return ++n;
    }

Zsh doesn't have the equivalent. You'll have to use a global parameter.

Roman.


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