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
|
@ -470,18 +470,22 @@ USAGE_LICENSE
|
|||
;
|
||||
|
||||
const char sh_optcommand[] =
|
||||
"[-1c?\n@(#)$Id: command (AT&T Research) 2003-08-01 $\n]"
|
||||
"[-1c?\n@(#)$Id: command (AT&T Research/ksh93) 2020-09-09 $\n]"
|
||||
USAGE_LICENSE
|
||||
"[+NAME?command - execute a simple command]"
|
||||
"[+NAME?command - execute a simple command disabling special properties]"
|
||||
"[+DESCRIPTION?Without \b-v\b or \b-V\b, \bcommand\b executes \acommand\a "
|
||||
"with arguments given by \aarg\a, suppressing the shell function lookup "
|
||||
"that normally occurs. In addition, if \acommand\a is a special "
|
||||
"built-in command, then the special properties are removed so that "
|
||||
"failures will not cause the script that executes it to terminate.]"
|
||||
"that normally occurs. If \acommand\a is a special built-in command, "
|
||||
"then the special properties are removed so that failures will not "
|
||||
"cause the script that executes it to terminate and preceding "
|
||||
"assignments will not persist beyond the command invocation. "
|
||||
"If \acommand\a is a declaration built-in command and the "
|
||||
"\b-o posix\b shell option is on, then the declaration properties are "
|
||||
"removed so that arguments containing \b=\b are not treated specially.]"
|
||||
"[+?With the \b-v\b or \b-V\b options, \bcommand\b is equivalent to the "
|
||||
"\bwhence\b(1) command.]"
|
||||
"[p?Causes a default path to be searched rather than the one defined by the "
|
||||
"value of \bPATH\b.]"
|
||||
"[p?Instead of \b$PATH\b, search the OS's default utility path as output by "
|
||||
"\bgetconf PATH\b.]"
|
||||
"[v?Equivalent to \bwhence\b \acommand\a [\aarg\a ...]].]"
|
||||
"[x?If \acommand\a fails because there are too many \aarg\as, it will be "
|
||||
"invoked multiple times with a subset of the arguments on each "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue