diff --git a/NEWS b/NEWS index 7eee354e5..7b9f48548 100644 --- a/NEWS +++ b/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. +2020-07-20: + +- If a shell function and a built-in command by the same name exist, + 'whence -a' and 'type -a' now report both. + 2020-07-19: - Fixed a crash that occured in the '.' command when using kshdb. diff --git a/src/cmd/ksh93/bltins/whence.c b/src/cmd/ksh93/bltins/whence.c index 300194c12..fb58133e6 100644 --- a/src/cmd/ksh93/bltins/whence.c +++ b/src/cmd/ksh93/bltins/whence.c @@ -138,7 +138,6 @@ static int whence(Shell_t *shp,char **argv, register int flags) register int aflag,r=0; register const char *msg; int tofree; - Dt_t *root; Namval_t *nq; char *notused; Pathcomp_t *pp=0; @@ -181,32 +180,36 @@ static int whence(Shell_t *shp,char **argv, register int flags) } /* built-ins and functions next */ bltins: - root = (flags&F_FLAG)?shp->bltin_tree:shp->fun_tree; - if(np= nv_bfsearch(name, root, &nq, ¬used)) + if(!(flags&F_FLAG) && (np = nv_bfsearch(name, shp->fun_tree, &nq, ¬used)) && !is_abuiltin(np)) { - if(is_abuiltin(np) && nv_isnull(np)) - goto search; - cp = ""; if(flags&V_FLAG) - { if(nv_isnull(np)) cp = sh_translate(is_ufunction); - else if(is_abuiltin(np)) - { - if(nv_isattr(np,BLT_SPC)) - cp = sh_translate(is_spcbuiltin); - else - cp = sh_translate(is_builtin); - } else cp = sh_translate(is_function); - } + else + cp = ""; + if(flags&Q_FLAG) + continue; + sfprintf(sfstdout,"%s%s\n",name,cp); + if(!aflag) + continue; + aflag++; + } + if((np = nv_bfsearch(name, shp->bltin_tree, &nq, ¬used)) && !nv_isnull(np)) + { + if(flags&V_FLAG) + if(nv_isattr(np,BLT_SPC)) + cp = sh_translate(is_spcbuiltin); + else + cp = sh_translate(is_builtin); + else + cp = ""; if(flags&Q_FLAG) continue; sfprintf(sfstdout,"%s%s\n",name,cp); if(!aflag) continue; - cp = 0; aflag++; } search: diff --git a/src/cmd/ksh93/data/builtins.c b/src/cmd/ksh93/data/builtins.c index 47d5ff128..460c43589 100644 --- a/src/cmd/ksh93/data/builtins.c +++ b/src/cmd/ksh93/data/builtins.c @@ -2017,9 +2017,9 @@ _JOB_ ; const char sh_optwhence[] = -"[-1c?\n@(#)$Id: whence (AT&T Research) 2007-04-24 $\n]" +"[-1c?\n@(#)$Id: whence (AT&T Research/ksh93) 2020-07-20 $\n]" USAGE_LICENSE -"[+NAME?whence - locate a command and describe its type]" +"[+NAME?whence, type - locate a command and describe its type]" "[+DESCRIPTION?Without \b-v\b, \bwhence\b writes on standard output an " "absolute pathname, if any, corresponding to \aname\a based " "on the complete search order that the shell uses. If \aname\a " @@ -2027,7 +2027,8 @@ USAGE_LICENSE "[+?If \b-v\b is specified, the output will also contain information " "that indicates how the given \aname\a would be interpreted by " "the shell in the current execution environment.]" -"[a?Displays all uses for each \aname\a rather than the first.]" +"[+?The \btype\b command is equivalent to \bwhence -v\b.]" +"[a?Like \b-v\b but displays all uses for each \aname\a rather than the first.]" "[f?Do not check for functions.]" "[p?Do not check to see if \aname\a is a reserved word, a built-in, " "an alias, or a function. This turns off the \b-v\b option.]" diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index de71efe99..ca5fcf8b0 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -17,4 +17,4 @@ * David Korn * * * ***********************************************************************/ -#define SH_RELEASE "93u+m 2020-07-19" +#define SH_RELEASE "93u+m 2020-07-20" diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index b9d9e297c..46a880b9d 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -753,6 +753,22 @@ $(whence -a -p printf | sed 's/^/printf is /')" [[ $actual == $expected ]] || err_exit "'whence -a': incorrect output" \ "(expected $(printf %q "$expected"), got $(printf %q "$actual"))" +# 'whence -a'/'type -a' failed to list builtin if function exists: https://github.com/ksh93/ksh/issues/83 +actual=$(printf() { :; }; whence -a printf) +expected="printf is a function +printf is a shell builtin +$(whence -a -p printf | sed 's/^/printf is /')" +[[ $actual == $expected ]] || err_exit "'whence -a': incorrect output for function+builtin" \ + "(expected $(printf %q "$expected"), got $(printf %q "$actual"))" + +# 'whence -a'/'type -a' failed to list builtin if autoload function exists: https://github.com/ksh93/ksh/issues/83 +actual=$(autoload printf; whence -a printf) +expected="printf is an undefined function +printf is a shell builtin +$(whence -a -p printf | sed 's/^/printf is /')" +[[ $actual == $expected ]] || err_exit "'whence -a': incorrect output for autoload+builtin" \ + "(expected $(printf %q "$expected"), got $(printf %q "$actual"))" + # ====== # 'cd ../.foo' should not exclude the '.' in '.foo' (