diff options
author | Denys Vlasenko | 2023-04-13 09:20:24 +0200 |
---|---|---|
committer | Denys Vlasenko | 2023-04-13 09:20:24 +0200 |
commit | 90b607d79a1377d6a5dda44ee112698c58432203 (patch) | |
tree | f8c9894cbf3c067cdb6e76ab312b24d5d65f331c /shell | |
parent | 8b72877babb20be9bb46c4437f5e1870390c29cc (diff) | |
download | busybox-90b607d79a1377d6a5dda44ee112698c58432203.zip busybox-90b607d79a1377d6a5dda44ee112698c58432203.tar.gz |
hush: quote variable values printed by "set" (match ash behavior)
function old new delta
builtin_set 258 301 +43
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 19 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/export-n.right | 4 |
2 files changed, 19 insertions, 4 deletions
diff --git a/shell/hush.c b/shell/hush.c index a938cc7..202c099 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -11147,6 +11147,12 @@ static int FAST_FUNC builtin_umask(char **argv) #if ENABLE_HUSH_EXPORT || ENABLE_HUSH_TRAP static void print_escaped(const char *s) { +//TODO? bash "set" does not quote variables which contain only alnums and "%+,-./:=@_~", +// (but "export" quotes all variables, even with only these chars). +// I think quoting strings with %+,=~ looks better +// (example: "set" printing var== instead of var='=' looks strange) +// IOW: do not quote "-./:@_": / is used in pathnames, : in PATH, -._ often in file names, @ in emails + if (*s == '\'') goto squote; do { @@ -11401,8 +11407,17 @@ static int FAST_FUNC builtin_set(char **argv) if (arg == NULL) { struct variable *e; - for (e = G.top_var; e; e = e->next) - puts(e->varstr); + for (e = G.top_var; e; e = e->next) { + const char *s = e->varstr; + const char *p = strchr(s, '='); + + if (!p) /* wtf? take next variable */ + continue; + /* var= */ + printf("%.*s", (int)(p - s) + 1, s); + print_escaped(p + 1); + putchar('\n'); + } return EXIT_SUCCESS; } diff --git a/shell/hush_test/hush-misc/export-n.right b/shell/hush_test/hush-misc/export-n.right index 3d55bf7..6079a01 100644 --- a/shell/hush_test/hush-misc/export-n.right +++ b/shell/hush_test/hush-misc/export-n.right @@ -2,8 +2,8 @@ export aaa1="'''" export aaa2='' export aaa3="'''"'abc' export aaa8='8' -aaa9=9 -aaa10=10 +aaa9='9' +aaa10='10' Nothing: Nothing: Nothing: |