From 0ba2f5f46ff781bd6073fcce7d80c1677f6a37e4 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 26 Oct 2026 14:26:58 -0500 Subject: [PATCH] Implement ${x@E} with tests --- tests/sh.test | 14 +++++++++++++- toys/pending/sh.c | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/sh.test b/tests/sh.test index 439b1223..f5dbbd67 100644 --- a/tests/sh.test +++ b/tests/sh.test @@ -183,7 +183,7 @@ tst 'escape makes argument' 'echo \ | wc -c' '2\n' tst 'single quote in double' "echo \"'\"" "'\n" # TODO needs shopt -s extglob progcomp -$BROKEN shxpect 'empty +() is literal' I$'shopt -s extglob progcomp\n' E$P \ +$BROKEN shxpect 'empty +() is literal' I$'shopt -s extglob progcomp\n' E"$P" \ I$'echo +()\n' O$'+()\n' shxpect '$_ preserved on assignment error' I$'true hello; a=1 b=2 c=${}\n' \ @@ -344,6 +344,18 @@ tst '${x,,} lowercase' 'LC_ALL=C.UTF-8 x=ȺȾ; echo "$x ${x,,} expanded without tst '${x,} lowercase' 'LC_ALL=C.UTF-8 x=ȺȾ; echo "$x ${x,} expanded without OOB"' \ 'ȺȾ ⱥȾ expanded without OOB\n' +shxpect '${x@E}1' I'a=\\a\\b\\e\\E\\f\\n\\r\\t\\v\\\\'$'\n' "E$P" \ + I$'echo -n "${a@E}" | xxd -pc0\n' O$'07081b1b0c0a0d090b5c\n' + +shxpect '${x@E}2' I'a=\\\'\''\\\"\\?\\123\\0123,\\xa\\x9a'$'\n' "E$P" \ + I$'echo -n "${a@E}" | xxd -pc0\n' O$'27223f530a332c0a9a\n' + +shxpect '${x@E}3' I'LC_ALL=C.UTF-8 a=\\u9a\\u89ab\\U3\\U1234face'$'\n' "E$P" \ + I$'echo -n "${a@E}" | xxd -pc0\n' O$'c29ae8a6ab03fc928d8fab8e\n' + +#\\\'\\\"\\?\\123\\0123,\\xa\\x9a,\\u9a\\u89ab,\\U3\\U1234face; echo "${a@E}" +#cat <(echo hello 1>&2)\n' E$'hello\n' E"$P" + mkdir -p abc/def/ghi touch www tst 'wildcards' 'echo w[v-x]w w[x-v]w abc/*/ghi' 'www w[x-v]w abc/def/ghi\n' diff --git a/toys/pending/sh.c b/toys/pending/sh.c index bbe3618c..fff014a8 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -2536,6 +2536,9 @@ barf: memcpy(ss = ifs+yy, toybuf, dd = ll); } if (cc=='u') break; + } else if (cc=='E') { + for (s = ifs, xx = 0; *s; jj++) xx += unescape2(ifs+xx, &s, 0); + ifs[xx] = 0; // } else if (cc=='Q') { // for (jj = xx = 0; ifs[jj]; jj++) //for (s = str+ii; *s != '\''; oo += wcrtomb(new+oo, unescape2(&s, 0),0)); -- 2.39.5