command
command in bash: Run command with arguments ignoring any shell function named command.
The '-p' option means to use a default value for $PATH that is guaranteed to find all of the standard utilities.
What exactly is the default PATH mentioned here? When I define export PATH="/home/ozgur/":$PATH
, don't I add a new PATH path over the default value?
## For Example
~$ export PATH="/home/ozgur/":$PATH
~$ echo $PATH
/home/ozgur/:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
~$ script.sh
hey, i am working !
~$ command -p script.sh
hey, i am working !
When I used the "-p" option of the command
command, I would expect it to ignore the new PATH path I had defined, but that didn't happen. What exactly am I missing here? What is the point of using the "-p" option if changes to the user's PATH path are not overridden with the "-p" option?
Best Answer
The
script.sh
command is hashed. If you runhash -r
, thencommand -p script.sh
will fail as expected. But if you run it directly, it will be hashed again.This really looks like a bug in bash -- it does not happen in other shells.