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

Re: Variable fails to increment with lvalue error



On Mon, Oct 23, 2023 at 5:28 PM Evan Clearfield <efclear@xxxxxxxxx> wrote:
>
> I then increment it with a simple call “(($count++))”, and when I run the script, I receive the error “bad math expression: lvalue required”

`$count` expands to `0`, so `(($count++))` is equivalent to `((0++))`.
The post-increment operator (++) requires something that can be
incremented (an lvalue). `0` is not an lvalue, so you get an error.
What you want instead is `((count++))`. This will increment `count` as
you expect.

Roman.




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