mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] hush: expand variables before globbing in for loops
Date: Thu, 21 Feb 2013 15:17:13 +0100	[thread overview]
Message-ID: <1361456235-30969-1-git-send-email-s.hauer@pengutronix.de> (raw)

The following does work:

for i in *; do echo $i; done

but the following does not:

a="*"; for i in $a; do echo $i; done

This is because globbing in for loops takes place before the variable
is expanded. Fix this by explicitly expanding the variables before globbing.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/hush.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/common/hush.c b/common/hush.c
index 1f468f6..5927ad6 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1008,7 +1008,11 @@ static int xglob(o_string *dest, int flags, glob_t *pglob, int glob_needed)
 			return 0;
 		}
 	} else if (glob_needed) {
-		gr = do_glob(dest->data, flags, NULL, pglob);
+		char *data;
+		data = insert_var_value(dest->data);
+		gr = do_glob(data, flags, NULL, pglob);
+		if (data != dest->data)
+			free(data);
 		debug("glob returned %d\n",gr);
 	} else {
 		gr = fake_glob(dest->data, flags, NULL, pglob);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2013-02-21 14:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-21 14:17 Sascha Hauer [this message]
2013-02-21 14:17 ` [PATCH 2/2] hush: implement $* Sascha Hauer
2013-02-22  8:13 ` [PATCH 1/2] hush: expand variables before globbing in for loops Sascha Hauer

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=1361456235-30969-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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