mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix 'command' expansion bug and POSIX compliance
The 'command' name can now result from an expansion, e.g.: c=command; "$c" ls set -- command ls; "$@" both work now. This fixes BUG_CMDEXPAN. If -o posix is on, 'command' now disables not only the "special" but also the "declaration" properties of builtin commands that it invokes. This is because POSIX specifies 'command' as a simple regular builtin, and any command name following 'command' is just an argument to the 'command' command, so there is nothing that allows any further arguments (such as assignment-arguments) to be treated specially by the parser. So, if and only if -o posix is on: a. Arguments that start with a variable name followed by '=' are always treated as regular words subject to normal shell syntax. b. Since assignment-arguments are not processed as assignments before the command itself, 'command' can now stop the shell from exiting (as required by the standard) if a command that it invokes (such as 'export') tries to modify a readonly variable. This fixes BUG_CMDSPEXIT. Most of 'command' is integrated in the parser and parse tree executer, so that is where it needed fixing. src/cmd/ksh93/sh/parse.c: simple(): - If the posix option is on, do not skip past SYSCOMMAND so that any declaration builtin commands that are arguments to 'command' are not detected and thus not treated specially at parsetime. src/cmd/ksh93/sh/xec.c: sh_exec(): - When detecting SYSCOMMAND in order to skip past it, not only compare the Namval_t pointer 'np' to SYSCOMMAND, but also handle the case where that pointer is NULL, as when the command name results from an expansion. In that case, search the function tree shp->fun_tree for the name and see if that yields the SYSCOMMAND pointer. fun_tree is initialised with a dtview to bltin_tree, so searching fun_tree instead allows for overriding 'command' with a shell function (which the POSIX standard requires us to allow). src/cmd/ksh93/sh.1, src/cmd/ksh93/data/builtins.c: - Update documentation to match these changes. - Various related edits and improvements. src/cmd/ksh93/tests/builtins.sh: - Check that 'command' works if resulting from an expansion. - Check that 'command' can be overridden by a shell function.
This commit is contained in:
parent
092b90da81
commit
b9d10c5a9c
8 changed files with 114 additions and 74 deletions
14
NEWS
14
NEWS
|
@ -3,6 +3,20 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2020-09-11:
|
||||
|
||||
- The 'command' regular builtin utility (which runs a simple command, removing
|
||||
special properties) has been made fully POSIX compliant.
|
||||
1. The 'command' name can now result from an expansion (fixing BUG_CMDEXPAN),
|
||||
e.g. 'c=command; "$c" ls' and 'set -- command ls; "$@"' now work.
|
||||
2. If and only if the POSIX mode (the new -o posix shell option) is active,
|
||||
then the 'command' utility now disables not only "special" but also
|
||||
"declaration" properties of builtin commands that it invokes, meaning:
|
||||
a. arguments that start with a variable name followed by '=' are
|
||||
always treated as regular words subject to normal shell syntax;
|
||||
b. 'command' can now stop the shell from exiting if a command that it
|
||||
invokes tries to modify a readonly variable (fixing BUG_CMDSPEXIT).
|
||||
|
||||
2020-09-09:
|
||||
|
||||
- Fixed BUG_LOOPRET2 and related bugs. The 'exit' and 'return' commands without
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue