aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-04-13 09:20:24 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-04-13 09:20:24 +0200
commit90b607d79a1377d6a5dda44ee112698c58432203 (patch)
treef8c9894cbf3c067cdb6e76ab312b24d5d65f331c
parent8b72877babb20be9bb46c4437f5e1870390c29cc (diff)
downloadbusybox-w32-90b607d79a1377d6a5dda44ee112698c58432203.tar.gz
busybox-w32-90b607d79a1377d6a5dda44ee112698c58432203.tar.bz2
busybox-w32-90b607d79a1377d6a5dda44ee112698c58432203.zip
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>
-rw-r--r--shell/hush.c19
-rw-r--r--shell/hush_test/hush-misc/export-n.right4
2 files changed, 19 insertions, 4 deletions
diff --git a/shell/hush.c b/shell/hush.c
index a938cc790..202c0993a 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -11147,6 +11147,12 @@ static int FAST_FUNC builtin_umask(char **argv)
11147#if ENABLE_HUSH_EXPORT || ENABLE_HUSH_TRAP 11147#if ENABLE_HUSH_EXPORT || ENABLE_HUSH_TRAP
11148static void print_escaped(const char *s) 11148static void print_escaped(const char *s)
11149{ 11149{
11150//TODO? bash "set" does not quote variables which contain only alnums and "%+,-./:=@_~",
11151// (but "export" quotes all variables, even with only these chars).
11152// I think quoting strings with %+,=~ looks better
11153// (example: "set" printing var== instead of var='=' looks strange)
11154// IOW: do not quote "-./:@_": / is used in pathnames, : in PATH, -._ often in file names, @ in emails
11155
11150 if (*s == '\'') 11156 if (*s == '\'')
11151 goto squote; 11157 goto squote;
11152 do { 11158 do {
@@ -11401,8 +11407,17 @@ static int FAST_FUNC builtin_set(char **argv)
11401 11407
11402 if (arg == NULL) { 11408 if (arg == NULL) {
11403 struct variable *e; 11409 struct variable *e;
11404 for (e = G.top_var; e; e = e->next) 11410 for (e = G.top_var; e; e = e->next) {
11405 puts(e->varstr); 11411 const char *s = e->varstr;
11412 const char *p = strchr(s, '=');
11413
11414 if (!p) /* wtf? take next variable */
11415 continue;
11416 /* var= */
11417 printf("%.*s", (int)(p - s) + 1, s);
11418 print_escaped(p + 1);
11419 putchar('\n');
11420 }
11406 return EXIT_SUCCESS; 11421 return EXIT_SUCCESS;
11407 } 11422 }
11408 11423
diff --git a/shell/hush_test/hush-misc/export-n.right b/shell/hush_test/hush-misc/export-n.right
index 3d55bf752..6079a0124 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="'''"
2export aaa2='' 2export aaa2=''
3export aaa3="'''"'abc' 3export aaa3="'''"'abc'
4export aaa8='8' 4export aaa8='8'
5aaa9=9 5aaa9='9'
6aaa10=10 6aaa10='10'
7Nothing: 7Nothing:
8Nothing: 8Nothing:
9Nothing: 9Nothing: