12

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?

  • 1
    I cannot reproduce this issue with bash v4.3.48. – John Bollinger Sep 6 at 11:46
16

What exactly am I missing here?

The script.sh command is hashed. If you run hash -r, then command -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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.