Sample Header Ad - 728x90

Bash builtin 'command' ignoring option '-p'

3 votes
1 answer
326 views
I am trying to add this to my ~/.bashrc and test for some commands, that already have aliases.
command -pv
but it seems like the -p option that is supposed to force a path search is getting ignored. Not sure if it's a bug to report so I decided to inquire in case i'm missing anything. **Tests**
Bash Version: 5.2
Patch Level: 37
Release Status: release
I make sure its the shell builtin
$ type command
command is a shell builtin

$ command --help
command: command [-pVv] command [arg ...]
    Execute a simple command or display information about commands.

    Runs COMMAND with ARGS suppressing  shell function lookup, or display
    information about the specified COMMANDs.  Can be used to invoke commands
    on disk when a function with the same name exists.

    Options:
      -p    use a default value for PATH that is guaranteed to find all of
            the standard utilities
      -v    print a description of COMMAND similar to the `type' builtin
      -V    print a more verbose description of each COMMAND

    Exit Status:
    Returns exit status of COMMAND, or failure if COMMAND is not found.
Works on aliases
$ command -v pacman
alias pacman='pacman --color auto'

$ command -v grep
alias grep='grep --color=auto'
But completely ignores '-p' however specified.
$ command -pv grep
alias grep='grep --color=auto'

$ command -p -v grep
alias grep='grep --color=auto'
Here, I tried to sneak in an unknown option to make sure it detects '-p' but simply ignores it.
$ command -p -v -x grep
bash: command: -x: invalid option
command: usage: command [-pVv] command [arg ...]
**Extra notes** In the zsh shell, everything seems to work fine, the -p option is treated as it should (I am not including zsh tests because this is about bash).
Asked by Jore (143 rep)
Nov 27, 2024, 04:41 AM
Last activity: Nov 27, 2024, 10:44 AM