mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 03:32:24 +00:00
Fix ${!foo@} and ${!foo*} to include 'foo' itself in search
These expansions are supposed to yield all variable names beginning with the indicated prefix. This should include the variable name that is identical to the prefix (as 'prefix' begins with 'prefix'). This bugfix is backported from the abandoned ksh 93v- beta, so AT&T intended this change. It also makes ksh work like bash in this. src/cmd/ksh93/sh/macro.c: varsub(): M_NAMESCAN: - Check if the prefix itself exists. If so, start with that. src/cmd/ksh93/tests/variables.sh: - Add tests for these expansions. src/cmd/ksh93/sh.1: - Fix the incomplete documentation of these expansions. src/cmd/ksh93/COMPATIBILITY: - Note the change as it's potentially incompatible in corner cases. Resolves: https://github.com/ksh93/ksh/issues/183
This commit is contained in:
parent
e58637752a
commit
4a8072e826
6 changed files with 32 additions and 3 deletions
5
NEWS
5
NEWS
|
@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2021-03-09:
|
||||
|
||||
- The ${!foo@} and ${!foo*} expansions yield variable names beginning with foo,
|
||||
but excluded 'foo' itself. The fix for this is now backported from 93v- beta.
|
||||
|
||||
2021-03-07:
|
||||
|
||||
- Fixed the typeset -p display of short integers without an assigned value.
|
||||
|
|
|
@ -96,6 +96,9 @@ For more details, see the NEWS file and for complete details, see the git log.
|
|||
match a normal (non-**) glob pattern. For example, if '/lnk' is a
|
||||
symlink to a directory, '/lnk/**' and '/l?k/**' now work as expected.
|
||||
|
||||
18. The variable name search expansions ${!prefix@} and ${!prefix*} now
|
||||
also include the variable 'prefix' itself in the possible results.
|
||||
|
||||
____________________________________________________________________________
|
||||
|
||||
KSH-93 VS. KSH-88
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
||||
#define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */
|
||||
#define SH_RELEASE_DATE "2021-03-07" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_DATE "2021-03-09" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
|
||||
|
||||
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
||||
|
|
|
@ -1274,9 +1274,14 @@ and
|
|||
inclusive using the same quoting rules as
|
||||
.BR @ .
|
||||
.TP
|
||||
.PD 0
|
||||
\f3${!\fP\f2prefix\^\fP\f3@}\fP
|
||||
.TP
|
||||
\f3${!\fP\f2prefix\^\fP\f3*}\fP
|
||||
Expands to the names of the variables whose names begin with
|
||||
These both expand to the names of the variables whose names begin with
|
||||
.IR prefix .
|
||||
The expansions otherwise work like \f3$@\fP and \f3$*\fP, respectively
|
||||
(see under \f2Quoting\fP below).
|
||||
.TP
|
||||
\f3${\fP\f2parameter\^\fP\f3:\-\fP\f2word\^\fP\f3}\fP
|
||||
If
|
||||
|
|
|
@ -1517,10 +1517,15 @@ retry1:
|
|||
}
|
||||
else
|
||||
{
|
||||
/* M_NAMESCAN: ${!prefix@} or ${!prefix*}. These work like $@, $*. */
|
||||
dolmax = strlen(id);
|
||||
dolg = -1;
|
||||
nextname(mp,id,0);
|
||||
v = nextname(mp,id,dolmax);
|
||||
/* Check if the prefix (id) itself exists. If so, start with that. */
|
||||
if(nv_open(id,mp->shp->var_tree,NV_NOREF|NV_NOADD|NV_VARNAME|NV_NOFAIL))
|
||||
v = id;
|
||||
else
|
||||
v = nextname(mp,id,dolmax);
|
||||
}
|
||||
}
|
||||
else if(type==M_SUBNAME)
|
||||
|
|
|
@ -1247,5 +1247,16 @@ exp=42.0000000000
|
|||
[[ $got == "$exp" ]] || err_exit "\${a:=b}: expansion not working for float type (expected '$exp', got '$got')"
|
||||
[[ $a == "$exp" ]] || err_exit "\${a:=b}: a was not assigned the correct float value (expected '$exp', got '$a')"
|
||||
|
||||
# ======
|
||||
# ${!FOO@} and ${!FOO*} expansions did not include FOO itself
|
||||
# https://github.com/ksh93/ksh/issues/183
|
||||
unset foo "${!foo@}"
|
||||
exp='foo foobar fool'
|
||||
got=$(IFS=/; foo=bar foobar=fbar fool=pity; print -r -- "${!foo@}")
|
||||
[[ $got == "$exp" ]] || err_exit "\${!foo@}: expected $(printf %q "$exp"), got $(printf %q "$got")"
|
||||
exp='foo/foobar/fool'
|
||||
got=$(IFS=/; foo=bar foobar=fbar fool=pity; print -r -- "${!foo*}")
|
||||
[[ $got == "$exp" ]] || err_exit "\${!foo*}: expected $(printf %q "$exp"), got $(printf %q "$got")"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Reference in a new issue