sh: Allow command -pv and command -pV (lookup using _PATH_STDPATH).
This commit is contained in:
parent
1aa8466f89
commit
8e6aa134e5
@ -1023,7 +1023,7 @@ commandcmd(int argc, char **argv)
|
||||
if (cmd != -1) {
|
||||
if (argc != 1)
|
||||
error("wrong number of arguments");
|
||||
return typecmd_impl(2, argv - 1, cmd);
|
||||
return typecmd_impl(2, argv - 1, cmd, path);
|
||||
}
|
||||
if (argc != 0) {
|
||||
old = handler;
|
||||
|
@ -720,7 +720,7 @@ unsetfunc(const char *name)
|
||||
*/
|
||||
|
||||
int
|
||||
typecmd_impl(int argc, char **argv, int cmd)
|
||||
typecmd_impl(int argc, char **argv, int cmd, const char *path)
|
||||
{
|
||||
struct cmdentry entry;
|
||||
struct tblentry *cmdp;
|
||||
@ -729,6 +729,9 @@ typecmd_impl(int argc, char **argv, int cmd)
|
||||
int i;
|
||||
int error1 = 0;
|
||||
|
||||
if (path != pathval())
|
||||
clearcmdentry(0);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
/* First look at the keywords */
|
||||
for (pp = parsekwd; *pp; pp++)
|
||||
@ -761,17 +764,17 @@ typecmd_impl(int argc, char **argv, int cmd)
|
||||
}
|
||||
else {
|
||||
/* Finally use brute force */
|
||||
find_command(argv[i], &entry, 0, pathval());
|
||||
find_command(argv[i], &entry, 0, path);
|
||||
}
|
||||
|
||||
switch (entry.cmdtype) {
|
||||
case CMDNORMAL: {
|
||||
if (strchr(argv[i], '/') == NULL) {
|
||||
const char *path = pathval();
|
||||
const char *path2 = path;
|
||||
char *name;
|
||||
int j = entry.u.index;
|
||||
do {
|
||||
name = padvance(&path, argv[i]);
|
||||
name = padvance(&path2, argv[i]);
|
||||
stunalloc(name);
|
||||
} while (--j >= 0);
|
||||
if (cmd == TYPECMD_SMALLV)
|
||||
@ -821,6 +824,10 @@ typecmd_impl(int argc, char **argv, int cmd)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (path != pathval())
|
||||
clearcmdentry(0);
|
||||
|
||||
return error1;
|
||||
}
|
||||
|
||||
@ -831,5 +838,5 @@ typecmd_impl(int argc, char **argv, int cmd)
|
||||
int
|
||||
typecmd(int argc, char **argv)
|
||||
{
|
||||
return typecmd_impl(argc, argv, TYPECMD_TYPE);
|
||||
return typecmd_impl(argc, argv, TYPECMD_TYPE, pathval());
|
||||
}
|
||||
|
@ -71,6 +71,6 @@ void deletefuncs(void);
|
||||
void addcmdentry(const char *, struct cmdentry *);
|
||||
void defun(const char *, union node *);
|
||||
int unsetfunc(const char *);
|
||||
int typecmd_impl(int, char **, int);
|
||||
int typecmd_impl(int, char **, int, const char *);
|
||||
int typecmd(int, char **);
|
||||
void clearcmdentry(int);
|
||||
|
15
tools/regression/bin/sh/builtins/command6.0
Normal file
15
tools/regression/bin/sh/builtins/command6.0
Normal file
@ -0,0 +1,15 @@
|
||||
# $FreeBSD$
|
||||
PATH=/var/empty
|
||||
command -pV ls
|
||||
command -pV true
|
||||
command -pV /bin/ls
|
||||
|
||||
fun() {
|
||||
}
|
||||
command -pV fun
|
||||
command -pV break
|
||||
command -pV if
|
||||
command -pV {
|
||||
|
||||
alias foo=bar
|
||||
command -pV foo
|
8
tools/regression/bin/sh/builtins/command6.0.stdout
Normal file
8
tools/regression/bin/sh/builtins/command6.0.stdout
Normal file
@ -0,0 +1,8 @@
|
||||
ls is /bin/ls
|
||||
true is a shell builtin
|
||||
/bin/ls is /bin/ls
|
||||
fun is a shell function
|
||||
break is a special shell builtin
|
||||
if is a shell keyword
|
||||
{ is a shell keyword
|
||||
foo is an alias for bar
|
29
tools/regression/bin/sh/builtins/command7.0
Normal file
29
tools/regression/bin/sh/builtins/command7.0
Normal file
@ -0,0 +1,29 @@
|
||||
# $FreeBSD$
|
||||
|
||||
failures=0
|
||||
|
||||
check() {
|
||||
if ! eval "[ $* ]"; then
|
||||
echo "Failed: $*"
|
||||
: $((failures += 1))
|
||||
fi
|
||||
}
|
||||
|
||||
check '"$(PATH=/libexec command -V ld-elf.so.1)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"'
|
||||
check '"$(PATH=/libexec command -V ld-elf.so.1; :)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"'
|
||||
check '"$(PATH=/libexec command -pv ld-elf.so.1)" = ""'
|
||||
check '"$(PATH=/libexec command -pv ld-elf.so.1; :)" = ""'
|
||||
|
||||
PATH=/libexec:$PATH
|
||||
|
||||
check '"$(command -V ld-elf.so.1)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"'
|
||||
check '"$(command -V ld-elf.so.1; :)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"'
|
||||
check '"$(command -pv ld-elf.so.1)" = ""'
|
||||
check '"$(command -pv ld-elf.so.1; :)" = ""'
|
||||
|
||||
PATH=/libexec
|
||||
|
||||
check '"$(command -v ls)" = ""'
|
||||
check '"$(command -pv ls)" = "/bin/ls"'
|
||||
|
||||
exit $((failures > 0))
|
Loading…
x
Reference in New Issue
Block a user