Skip to content

fix(builtins): command -v does not search PATH for external scripts #1120

@chaliy

Description

@chaliy

Problem

command -v <name> only checks builtins, functions, and keywords. It never searches PATH for external scripts/executables, so it always returns exit code 1 for anything that isn't a builtin.

Real bash behavior: command -v searches PATH and prints the resolved path (e.g. /usr/bin/foo).

Impact

Any bash script that uses command -v to check for external commands fails in bashkit. This is a very common bash pattern — e.g. the ticket CLI uses it for plugin discovery:

# ticket plugin dispatch (line ~1335)
for _prefix in tk ticket; do
    _plugin="${_prefix}-$1"
    if command -v "$_plugin" &>/dev/null; then  # <-- always fails in bashkit
        exec "$_plugin" "$@"
    fi
done

Direct invocation of the script works fine (ticket-ls succeeds), only the command -v check fails.

Root cause

In crates/bashkit/src/interpreter/mod.rs, execute_command_builtin() handles -v mode (around line 5089):

'v' => {
    let found = self.builtins.contains_key(cmd_name.as_str())
        || self.functions.contains_key(cmd_name.as_str())
        || is_keyword(cmd_name);
    // ... returns exit 1 if not found
}

It never calls try_execute_script_via_path_search() (line ~4123), which already implements correct PATH + VFS resolution and is used during actual command execution.

Fix

In the -v (and -V) branches of execute_command_builtin(), after checking builtins/functions/keywords, call the existing PATH search logic to check if the command resolves to an executable in any PATH directory via the VFS. If found, print the resolved path and return exit code 0.

The same applies to command -V (verbose mode), which should print something like ticket-ls is /ticket/plugins/ticket-ls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions