help-bash
[Top][All Lists]
Advanced

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

Re: regex capturing the left-hand side of =


From: Eli Schwartz
Subject: Re: regex capturing the left-hand side of =
Date: Sat, 10 Jul 2021 22:51:36 -0400

On 7/10/21 8:07 AM, Peng Yu wrote:
> Hi,
> 
> I want to capture the left-hand side of =.


I don't understand this? You already know the left hand side because you
know what you wrote, the assignment operator doesn't let you do expansions.


> Since bash variables can be at the left-hand side of =, it is easy to
> be captured this case by a regex like ^[A-Za-z_][A-Za-z0-9_]$.


I don't understand this? Bash variables can be on the right hand side,
not the left hand side. Valid names for a bash variable can be on the
left hand side... names, not actually variables.

You can't do

$var=foo


> But it is not easy to capture assignments to elements in arrays or
> associative arrays due to the complexity in the suffixes in between
> [].


What is so complex about it? You have a bash parser at /bin/bash which
can evaluate that complexity for you (at the time you run the script, no
less).


> Is there a regex that can capture and only capture all bash code
> snippets for the left-hand side of the assignment operator =?


So now there is supposed to be "bash code snippets" on the LHS of an
assignment operator??? How???

What are you trying to do? (I know, I know, anyone asking "what are you
trying to do" and expecting Peng Yu to answer is the most foolish fool
in the world. But I'm going to ask anyway, in order to establish
precedent in the discussion thread that "this question needs to be
answered and naive readers shouldn't get the erroneous impression this
thread is a good example to follow".)

Why are you even trying to "capture" anything here? Clearly this can't
be done inside of the script itself. Are you building a bash parser in
another language?


-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

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