From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD8EFC433EF for ; Mon, 22 Nov 2021 08:52:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A64C083731; Mon, 22 Nov 2021 09:52:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1637571129; bh=PXDs/fbOPZ+3I55WICvRycOl85f+vwbh2JA0A/C4Ofg=; h=To:cc:From:Subject:In-reply-to:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=X/+Ls3Hl6ortLPlzlY0+qmeAlBYPL5kYlydJTqvlVVH5E/eoIFFLoZUQgb9T/O2zq Blk+n8NVgvmebVkVQ8maXHBCUTSt6z+5VWDw7upp+aA9eihZIM9FzEpvXPvE8n7lUd Cy5MJ8RqJ8wf0/RraLRq6XFdlV04irOs+QUobbWEyCVkPPv9Hwah7lHDRzZa/V9/zw b0+fdsz9uNgclCE2pqShkLTJd6YndlxmIHKussGkCz0WJFDgPJus9W1B+5YQGpE4l5 GUnN3XEmxuDGNOXDoats3eLsDbKGIq5Z12kKjVFGEE2V1lzBYVl6yhAT+am0gDTvws mBh8kLpTiofbg== Received: from janitor.denx.de (unknown [62.91.23.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: noc@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id DB31583728 for ; Mon, 22 Nov 2021 09:52:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1637571126; bh=PXDs/fbOPZ+3I55WICvRycOl85f+vwbh2JA0A/C4Ofg=; h=To:cc:From:Subject:In-reply-to:References:Date:From; b=TmR7tSV933486ziJyhy/Qo+hGgLX+i004wrArcmOZxMSuPExGYUYa5eIXU41CeysW 2WoM61VnL+MKAHY0XNYLUSE0WHhI68+ytrs/RR5oQeVUE9nAdYofk6Fsx4lniPvK2K qaU+8F6k9WY52mZpbv0uC9cvS+WedcXKCI+JJxDSXkiKLm1p5pKZbg8enUkYasueM6 yxnMQvtbePWa4aJEsLnSxBehIfp2X8Fd58Z/u+USiuyKsUYsO8/1EeWSvQ8BRIBJvf RC39CRUjsWM5ybjNnp+v84v5kKCAnjJGf+ScnoxhhuGmvvFdHosncI1kvN/RvlQK77 E3qu1gWSJBwRg== Received: by janitor.denx.de (Postfix, from userid 108) id 8CA00A0262; Mon, 22 Nov 2021 09:52:06 +0100 (CET) Received: from gemini.denx.de (gemini.denx.de [10.4.0.2]) by janitor.denx.de (Postfix) with ESMTPS id D1346A0050; Mon, 22 Nov 2021 09:51:59 +0100 (CET) Received: from gemini.denx.de (localhost [IPv6:::1]) by gemini.denx.de (Postfix) with ESMTP id A59EB1E1813; Mon, 22 Nov 2021 09:51:59 +0100 (CET) To: Art Nikpal cc: Simon Glass , Tom Rini , marek.behun@nic.cz, Neil Armstrong , Tom Warren , Andre Przywara , U-Boot Mailing List , u-boot-amlogic@groups.io, Christian Hewitt , Artem Lapkin , Nick Xie , Gouwa Wang , Francis Laniel From: Wolfgang Denk Subject: Re: [PATCH v2 0/2] env: setenv add resolve value option MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8bit In-reply-to: References: <20211119043647.1251416-1-art@khadas.com> <2004466.1637308134@gemini.denx.de> <6198ebca.1c69fb81.fc50c.bf0bSMTPIN_ADDED_BROKEN@mx.google.com> Comments: In-reply-to Art Nikpal message dated "Mon, 22 Nov 2021 16:09:10 +0800." Date: Mon, 22 Nov 2021 09:51:59 +0100 Message-ID: <2497688.1637571119@gemini.denx.de> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Dear Artem, In message 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.