public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: Art Nikpal <email2tema@gmail.com>
Cc: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
	marek.behun@nic.cz, Neil Armstrong <narmstrong@baylibre.com>,
	Tom Warren <twarren@nvidia.com>,
	Andre Przywara <andre.przywara@arm.com>,
	U-Boot Mailing List <u-boot@lists.denx.de>,
	u-boot-amlogic@groups.io,
	Christian Hewitt <christianshewitt@gmail.com>,
	Artem Lapkin <art@khadas.com>, Nick Xie <nick@khadas.com>,
	Gouwa Wang <gouwa@khadas.com>,
	Francis Laniel <francis.laniel@amarulasolutions.com>
Subject: Re: [PATCH v2 0/2] env: setenv add resolve value option
Date: Mon, 22 Nov 2021 09:51:59 +0100	[thread overview]
Message-ID: <2497688.1637571119@gemini.denx.de> (raw)
In-Reply-To: <CAKaHn9+yL3naiDqbsQJWQ0Po=g=TmjjcPSKxkx5C4ay1M1AsUA@mail.gmail.com>

Dear Artem,

In message <CAKaHn9+yL3naiDqbsQJWQ0Po=g=TmjjcPSKxkx5C4ay1M1AsUA@mail.gmail.com> you wrote:
> > >
> > > next examples just demonstrate how its works for already defined env
> > > variables which contain other variables (like storred env variables)
> >
> > Which next examples?
>
> Usage examples (from commit message):
>
> => setenv a hello; setenv b world; setenv c '${a} ${b}'
> => setenv -r d '${c}! ${a}...'
> => printenv d
> d=hello world! hello...

This is a very simple example, and I showed you how you can solve
this one by just omitting the apostrophes:

=> setenv a hello; setenv b world; setenv c ${a} ${b}
=> setenv d ${c}! ${a}...
=> printenv d
d=hello world! hello...


I _think_ what you actually have in mind is something like this:

=> setenv a hello
=> setenv b world
=> setenv c '${a} ${b}'
=> setenv a goodbye
=> setenv b sunshine

something to set d to: '${c}! ${a}...'

=> printenv d

Here my simple approach does not show what you want to have:

=> setenv a hello
=> setenv b world
=> setenv c ${a} ${b}
=> setenv a goodbye
=> setenv b sunshine
=> setenv d ${c}! ${a}...
=> printenv d
d=hello world! goodbye...

That's because here evaluation takes place at assignment, but you
want it when used - but being recursive here is neither a good idea
nor standard.

How would you do it in a standard posix shell?  You would have to
use "eval", like that:

$ a=hello
$ b=world
$ c='${a} ${b}'
$ a=goodbye
$ b=sunshine
$ d=$(eval echo $c)
$ echo $d
goodbye sunshine

But please note that "eval" is _not_ recursive!!

$ a='$b'
$ eval echo $c
$b sunshine

And this is why I object against this patch.

Oh, and in U-Boot you could write this as:

=> setenv a hello
=> setenv b world
=> setenv c '${a} ${b}'
=> setenv a goodbye
=> setenv b sunshine
=> setenv foo "setenv d ${c}! ${a}..."
=> run foo
=> printenv d                         
d=goodbye sunshine! goodbye...

And yes, here you have to be careful about using ' or " as there is
no recursion like you might expect.

So yes, it would be nice if we had "eval" (which will ocme with the
hush update), and no, "eval" does not recurse either.



Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Real computer scientists despise the idea of actual  hardware.  Hard-
ware has limitations, software doesn't. It's a real shame that Turing
machines are so poor at I/O.

  reply	other threads:[~2021-11-22  8:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19  4:36 [PATCH v2 0/2] env: setenv add resolve value option Artem Lapkin
2021-11-19  4:36 ` [PATCH v2 1/2] " Artem Lapkin
2021-11-25  0:13   ` Simon Glass
2022-04-07 18:05   ` Tom Rini
2022-04-08 13:09     ` Sean Anderson
2022-04-08 13:11       ` Tom Rini
2021-11-19  4:36 ` [PATCH v2 2/2] test: env: deep resolve value testing Artem Lapkin
2021-11-25  0:13   ` Simon Glass
2021-11-19  7:48 ` [PATCH v2 0/2] env: setenv add resolve value option Wolfgang Denk
2021-11-19  9:06   ` Art Nikpal
2021-11-20 12:36     ` Wolfgang Denk
2021-11-22  8:25       ` Art Nikpal
     [not found]     ` <6198ebca.1c69fb81.fc50c.bf0bSMTPIN_ADDED_BROKEN@mx.google.com>
2021-11-22  8:09       ` Art Nikpal
2021-11-22  8:51         ` Wolfgang Denk [this message]
2021-11-22 10:06           ` Art Nikpal

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=2497688.1637571119@gemini.denx.de \
    --to=wd@denx.de \
    --cc=andre.przywara@arm.com \
    --cc=art@khadas.com \
    --cc=christianshewitt@gmail.com \
    --cc=email2tema@gmail.com \
    --cc=francis.laniel@amarulasolutions.com \
    --cc=gouwa@khadas.com \
    --cc=marek.behun@nic.cz \
    --cc=narmstrong@baylibre.com \
    --cc=nick@khadas.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=twarren@nvidia.com \
    --cc=u-boot-amlogic@groups.io \
    --cc=u-boot@lists.denx.de \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox