bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parser bug in Q_ARITH


From: Robert Elz
Subject: Re: parser bug in Q_ARITH
Date: Tue, 15 Jul 2025 14:21:49 +0700

    Date:        Mon, 14 Jul 2025 15:22:35 -0400
    From:        Chet Ramey <chet.ramey@case.edu>
    Message-ID:  <90a41c5d-c407-4a36-b7b1-21a9201b4bc1@case.edu>

  | Say you have something like
  |
  | if command; then
  |     declare -i X
  |     X=some-random-expression
  | fi
  |
  | How does the parser determine the assignment should be parsed as an
  | arithmetic expression?

There is a much better example of the problem:

func() {
        if eval "$1"; then
                declare -i X=something
        else
                unset X
        fi
        X=whatever-you-like
}

Now work out how to parse things in a context dependent way.

What's more, all this needs to work, and to be consistent, and
logical for the user to understand.

And note that "whatever..." may contain any kind of expansion,
including $(( )) any kind of var reference, including to $X, including
using that as an index into some kind of array.

kre



reply via email to

[Prev in Thread] Current Thread [Next in Thread]