summaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/shell/ash.c b/shell/ash.c
index b404449..2cebfe2 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -11728,16 +11728,9 @@ parsesub: {
subtype = VSNORMAL;
if (c == '{') {
c = pgetc_eatbnl();
- if (c == '#') {
- c = pgetc_eatbnl();
- if (c == '}')
- c = '#'; /* ${#} - same as $# */
- else
- subtype = VSLENGTH; /* ${#VAR} */
- } else {
- subtype = 0;
- }
+ subtype = 0;
}
+ varname:
if (c <= 255 /* not PEOA or PEOF */ && is_name(c)) {
/* $[{[#]]NAME[}] */
do {
@@ -11752,8 +11745,23 @@ parsesub: {
} while (isdigit(c));
} else if (is_special(c)) {
/* $[{[#]]<specialchar>[}] */
- USTPUTC(c, out);
+ int cc = c;
+
c = pgetc_eatbnl();
+ if (!subtype && cc == '#') {
+ subtype = VSLENGTH;
+ if (c == '_' || isalnum(c))
+ goto varname;
+ cc = c;
+ c = pgetc_eatbnl();
+ if (cc == '}' || c != '}') {
+ pungetc();
+ subtype = 0;
+ c = cc;
+ cc = '#';
+ }
+ }
+ USTPUTC(cc, out);
} else {
goto badsub;
}