From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>,
Evan Clearfield <efclear@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Variable fails to increment with lvalue error
Date: Mon, 23 Oct 2023 19:03:08 +0200 [thread overview]
Message-ID: <CAN=4vMpf=APBM+WwuqC9JcntFcEcBjRRpMXEH7XggbBaAHhXxg@mail.gmail.com> (raw)
In-Reply-To: <1372623164.1448847.1698079437641@mail.virginmedia.com>
On Mon, Oct 23, 2023 at 6:44 PM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> > On 23/10/2023 16:33 Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> > On Mon, Oct 23, 2023 at 5:28 PM Evan Clearfield <efclear@gmail.com> 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++))`.
>
> Is it worth drawing attention to this, or is this just excess verbiage?
>
> pws
>
> diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo
> index bc3e35ad5..e6380b2cb 100644
> --- a/Doc/Zsh/arith.yo
> +++ b/Doc/Zsh/arith.yo
> @@ -23,8 +23,10 @@ command which begins with a `tt(LPAR()LPAR())', all the characters until a
> matching `tt(RPAR()RPAR())' are treated as a double-quoted expression and
> arithmetic expansion performed as for an argument of tt(let). More
> precisely, `tt(LPAR()LPAR())var(...)tt(RPAR()RPAR())' is equivalent to
> -`tt(let ")var(...)tt(")'. The return status is 0 if the arithmetic value
> -of the expression is non-zero, 1 if it is zero, and 2 if an error occurred.
> +`tt(let ")var(...)tt(")': note the presence of double quotes, so that variable
> +expansion etc. takes place before arithmetic evaluation. The return
> +status is 0 if the arithmetic value of the expression is non-zero, 1 if
> +it is zero, and 2 if an error occurred.
>
> For example, the following statement
>
> @@ -37,6 +39,10 @@ example(let "val = 2 + 1")
> both assigning the value 3 to the shell variable tt(val) and returning a
> zero status.
>
> +Note further that it would be incorrect to replace tt(val) with tt($val)
> +as the latter is affected by double quote substitution, so that
> +arithmetic evaluation does not see the name of the variable.
> +
> cindex(arithmetic base)
> cindex(bases, in arithmetic)
> Integers can be in bases other than 10.
>
Let's ask the OP if this would've been helpful.
Evan, have you read this documentation page? It's available at `man
zshmisc` and online at
https://zsh.sourceforge.io/Doc/Release/Arithmetic-Evaluation.html. If
you have, would it have helped if the docs were amended as per Peter's
patch?
Roman.
next prev parent reply other threads:[~2023-10-23 17:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 15:27 Evan Clearfield
2023-10-23 15:33 ` Roman Perepelitsa
2023-10-23 16:43 ` Peter Stephenson
2023-10-23 17:03 ` Roman Perepelitsa [this message]
2023-10-23 18:21 ` Ray Andrews
2023-10-23 16:34 ` Dominik Vogt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAN=4vMpf=APBM+WwuqC9JcntFcEcBjRRpMXEH7XggbBaAHhXxg@mail.gmail.com' \
--to=roman.perepelitsa@gmail.com \
--cc=efclear@gmail.com \
--cc=p.w.stephenson@ntlworld.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).