summaryrefslogtreecommitdiffstats
path: root/bin/sh/eval.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-06-09 23:12:23 +0000
committerjilles <jilles@FreeBSD.org>2011-06-09 23:12:23 +0000
commitbd55770c9432e60436b620cca0048948daf2445b (patch)
treeb5956f74d11c058a2de8b33b881512251747fa47 /bin/sh/eval.c
parent3f51f93516b6d0ace5d5e577719f1073770d5170 (diff)
downloadFreeBSD-src-bd55770c9432e60436b620cca0048948daf2445b.zip
FreeBSD-src-bd55770c9432e60436b620cca0048948daf2445b.tar.gz
sh: Do parameter expansion before printing PS4 (set -x).
The function name expandstr() and the general idea of doing this kind of expansion by treating the text as a here document without end marker is from dash. All variants of parameter expansion and arithmetic expansion also work (the latter is not required by POSIX but it does not take extra code and many other shells also allow it). Command substitution is prevented because I think it causes too much code to be re-entered (for example creating an unbounded recursion of trace lines). Unfortunately, our LINENO is somewhat crude, otherwise PS4='$LINENO+ ' would be quite useful.
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r--bin/sh/eval.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 585f91e..92a18e4 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -745,8 +745,9 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
/* Print the command if xflag is set. */
if (xflag) {
char sep = 0;
- const char *p;
- out2str(ps4val());
+ const char *p, *ps4;
+ ps4 = expandstr(ps4val());
+ out2str(ps4 != NULL ? ps4 : ps4val());
for (sp = varlist.list ; sp ; sp = sp->next) {
if (sep != 0)
out2c(' ');
OpenPOWER on IntegriCloud