I found another minor POSIX bug in mksh 'command': the options -p and -v don't combine correctly.
The -p flag means that 'command' will search the system default PATH instead of the current PATH, but does not change that builtins take precedence over external commands. Hence 'command -p test' will execute the 'test' builtin and not /bin/test. '-v' output should reflect what would actually be executed without that flag. Without the -p flag, this works fine: $ command -v true true However, command -pv always shows the external command, even if command -p does not execute it: $ command -pv [ /bin/[ (expected output: '[') $ command -p [ mksh: [: missing ] ^^^^ it's the builtin, as expected This also means that 'command -pv' should find shell keywords such as 'if' the same way 'command -v' should (as is the behaviour on ksh93, bash, dash, etc.), so my earlier patch for 'command' of 1 July also needs to be amended. $ command -pv if (nothing, expected output: if) I believe the following patch fixes it (without affecting 'whence -p'). Thanks, - M. diff -ur mksh.orig/funcs.c mksh/funcs.c --- mksh.orig/funcs.c 2016-01-20 22:34:37.000000000 +0100 +++ mksh/funcs.c 2016-02-14 23:27:54.000000000 +0100 @@ -548,15 +548,14 @@ * or whence -pv. This should be considered a feature. */ vflag = Vflag; - } - if (pflag) + } else if (pflag) fcflags &= ~(FC_BI | FC_FUNC); while ((vflag || rv == 0) && (id = *wp++) != NULL) { uint32_t h = 0; tp = NULL; - if (!pflag) + if (!iam_whence || !pflag) tp = ktsearch(&keywords, id, h = hash(id)); if (!tp && !pflag) { tp = ktsearch(&aliases, id, h ? h : hash(id));