Skip to contentSkip to conversation

common: cli_simple: Recursively parse variables

PATCH New Nishanth Menon 2 participants 2 messages Dec 4, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: cli_simple: Recursively parse variables

When we use the following in bootargs:
v1=abc
v2=123-${v1}
echo $v2
we get 123-${v1}
This is because we do not recursively check to see if v2 by itself has a hidden variable. Fix the same with recursive call

---

Testing with sandbox: http://pastebin.ubuntu.com/13672432/

 common/cli_simple.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
common/cli_simple.c +9 -3
index 9c3d073d583b..63bda32c57e4 100644
@@ -134,11 +134,17 @@ void cli_simple_process_macros(const char *input, char *output)
 				envval = getenv(envname);
 
 				/* Copy into the line if it exists */
-				if (envval != NULL)
-					while ((*envval) && outputcnt) {
-						*(output++) = *(envval++);
+				if (envval != NULL) {
+					char finalval[CONFIG_SYS_CBSIZE], *f;
+
+					cli_simple_process_macros(envval,
+								  finalval);
+					f = finalval;
+					while ((*f) && outputcnt) {
+						*(output++) = *(f++);
 						outputcnt--;
 					}
+				}
 				/* Look for another '$' */
 				state = 0;
 			}
Signature · 1 line
2.6.2.402.g2635c2b
#1 lore raw

PATCH 1/1 common: cli_simple: Recursively parse variables

Dear Nishanth Menon,

Quoted 7 lines · In message <[email protected]> you wrote:

When we use the following in bootargs:
v1=abc
v2=123-${v1}
echo $v2
we get 123-${v1}
This is because we do not recursively check to see if v2 by itself has a hidden variable. Fix the same with recursive call

Are you sure this is a good idea?

Current behaviour is what a standard shell would do as well:

bash$ v1=abc
bash$ v2='123-${v1}'
bash$ echo $v2
123-${v1}

I think your change would causes non-standard shell behaviour.

If you want to evaluate variables, you have to do so as part of a "run" command...

Best regards,

Wolfgang Denk

Signature · 5 lines
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 at denx.de
The trouble with our times is that the future is not what it used  to
be.                                                     - Paul Valery