Martijn Dekker schreef op 04-03-16 om 22:46: > Martijn Dekker schreef op 04-03-16 om 19:30: >> Some minor updates to the man page are also needed. I'll make a new patch. > Here's take 2.
It was correctly pointed out that I made some unrelated edits to sh.1 that would be better submitted and evaluated separately. Here's take 3. - M.
Index: bin/ksh/c_ksh.c =================================================================== RCS file: /cvs/src/bin/ksh/c_ksh.c,v retrieving revision 1.49 diff -u -p -u -r1.49 c_ksh.c --- bin/ksh/c_ksh.c 15 Jan 2016 17:55:45 -0000 1.49 +++ bin/ksh/c_ksh.c 4 Mar 2016 22:33:45 -0000 @@ -433,23 +433,23 @@ c_whence(char **wp) fcflags = FC_BI | FC_PATH | FC_FUNC; if (!iam_whence) { - /* Note that -p on its own is deal with in comexec() */ + /* Note that -p on its own is dealt with in comexec() */ if (pflag) fcflags |= FC_DEFPATH; - /* Convert command options to whence options - note that - * command -pV uses a different path search than whence -v - * or whence -pv. This should be considered a feature. + /* Convert command options to whence options. Note that + * command -pV and command -pv use a different path search + * than whence -v or whence -pv. This should be considered + * a feature. */ vflag = Vflag; - } - if (pflag) + } else if (pflag) fcflags &= ~(FC_BI | FC_FUNC); while ((vflag || ret == 0) && (id = *wp++) != NULL) { tp = NULL; - if ((iam_whence || vflag) && !pflag) + if (!iam_whence || !pflag) tp = ktsearch(&keywords, id, hash(id)); - if (!tp && !pflag) { + if (!tp && (!iam_whence || !pflag)) { tp = ktsearch(&aliases, id, hash(id)); if (tp && !(tp->flag & ISSET)) tp = NULL; Index: bin/ksh/ksh.1 =================================================================== RCS file: /cvs/src/bin/ksh/ksh.1,v retrieving revision 1.173 diff -u -p -u -r1.173 ksh.1 --- bin/ksh/ksh.1 29 Dec 2015 01:02:34 -0000 1.173 +++ bin/ksh/ksh.1 4 Mar 2016 22:33:48 -0000 @@ -2969,7 +2969,7 @@ is executed exactly as if had not been specified, with two exceptions: firstly, .Ar cmd -cannot be a shell function; +cannot be an alias or a shell function; and secondly, special built-in commands lose their specialness (i.e. redirection and utility errors do not cause the shell to exit, and command assignments are not permanent). @@ -2981,6 +2981,8 @@ option is given, a default search path i (the actual value of the default path is system dependent: on POSIX-ish systems, it is the value returned by .Ic getconf CS_PATH ) . +Nevertheless, reserved words, aliases, shell functions, and +builtin commands are still found before external commands. .Pp If the .Fl v @@ -4473,7 +4475,7 @@ is similar to .Ic command Fl v except that .Ic whence -will find reserved words and won't print aliases as alias commands. +won't print aliases as alias commands. With the .Fl v option, Index: bin/ksh/sh.1 =================================================================== RCS file: /cvs/src/bin/ksh/sh.1,v retrieving revision 1.130 diff -u -p -u -r1.130 sh.1 --- bin/ksh/sh.1 12 Oct 2015 12:34:42 -0000 1.130 +++ bin/ksh/sh.1 4 Mar 2016 22:33:48 -0000 @@ -329,6 +329,9 @@ but identify how the shell will interpre Do not invoke .Ar command , but identify the pathname the shell will use to run it. +For aliases, a command to define that alias is printed. +For shell reserved words, shell functions, and built-in utilities, +just the name is printed. .El .Pp The exit status is that of @@ -346,8 +349,9 @@ If the options or .Fl v are given, -the exit status is 0 on success, -or >0 if an error occurs. +the exit status is 0 if the +.Ar command +was found, or >0 if it was not found. .It Ic continue Op Ar n Go directly to the next iteration of the innermost .Ic for , while , Index: regress/bin/ksh/obsd-regress.t =================================================================== RCS file: /cvs/src/regress/bin/ksh/obsd-regress.t,v retrieving revision 1.1 diff -u -p -u -r1.1 obsd-regress.t --- regress/bin/ksh/obsd-regress.t 2 Dec 2013 20:39:44 -0000 1.1 +++ regress/bin/ksh/obsd-regress.t 4 Mar 2016 22:33:48 -0000 @@ -273,3 +273,75 @@ stdin: set foo bar baz ; for out in ; do echo $out ; done --- +name: command-pvV-posix-priorities +description: + For POSIX compatibility, command -v should find aliases and reserved + words, and command -p[vV] should find aliases, reserved words, and + builtins over external commands. +stdin: + PATH=/bin:/usr/bin + alias foo="bar baz" + bar() { :; } + for word in 'if' 'foo' 'bar' 'set' 'true'; do + command -v "$word" + command -pv "$word" + command -V "$word" + command -pV "$word" + done +expected-stdout: + if + if + if is a reserved word + if is a reserved word + alias foo='bar baz' + alias foo='bar baz' + foo is an alias for 'bar baz' + foo is an alias for 'bar baz' + bar + bar + bar is a function + bar is a function + set + set + set is a special shell builtin + set is a special shell builtin + true + true + true is a shell builtin + true is a shell builtin + +--- +name: whence-preserve-tradition +description: + POSIX 'command' and ksh88/pdksh-specific 'whence' are handled by the + same c_whence() function. This regression test is to ensure that + the POSIX compatibility changes for 'command' (see previous test) do + not affect traditional 'whence' behaviour. +stdin: + PATH=/bin:/usr/bin + alias foo="bar baz" + bar() { :; } + for word in 'if' 'foo' 'bar' 'set' 'true'; do + whence "$word" + whence -p "$word" + whence -v "$word" + whence -pv "$word" + done +expected-stdout: + if + if is a reserved word + if not found + 'bar baz' + foo is an alias for 'bar baz' + foo not found + bar + bar is a function + bar not found + set + set is a special shell builtin + set not found + true + /usr/bin/true + true is a shell builtin + true is a tracked alias for /usr/bin/true +---