`command -p` Not Searching Path
Nathan Royce <[email protected]>
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <CALaQ_hrYRcp1_+1KPx9UXMtMb8UgRRJCRj9Y6JBCc73ogO7jmw@mail.gmail.com> |
This might relate to, or be in a similar vain as "Why does the command builtin not circumvent invocation of builtins?" (https://lore.kernel.org/dash/[email protected]/) I had thoughts about how aliases, functions, built-ins, executables behave in a shell, and came across https://stackoverflow.com/a/64028240 which I thought was great. I tested the concept in dash, and did not get the expected results (specifically relating to `command -p`)... Setup: 1) $ echo () { printf "%s\n" "hey function"; } //first, otherwise 1) and 2) swapped will fail at 2) 2) $ alias echo='printf "%s\n" "hey alias"' 3) $ mv /usr/bin/echo /usr/bin/echo.bak 4) $ cp /usr/bin/ls /usr/bin/echo Tests: 1) $ echo //from alias 2) $ \echo //from function 3) $ "echo" //from function. Just thought to test that just now 4) $ command echo //Presumably from built-in ***5) $ command -p echo //SHOULD have been from PATH, which we made to be a copy of `ls` 6) $ which echo ///usr/bin/echo 7) $ ls -l /usr/bin/echo /usr/bin/ls //both size 166640 I don't know why 5) behaves that way for echo. I already have `ls` as a function (for coloring), and went ahead and added it as an alias as "echo alias", and `command -p ls` properly used the executable in PATH (non-colored output). That was done in a clean environment ($ exec dash) after the prior tests.