Check which command Bash will run with command -v and type -a

  • Published: 2026.10.25
  • Updated: 2026.10.25
  • Windows

A tool is installed, yet Bash cannot find it, selects a different version, or behaves differently in a terminal. An executable on disk is only one possibility: a name can also refer to a builtin, a function, or an active alias. Looking at the installation directory alone may miss what the shell is actually using.

Check how the current Bash session resolves the name before changing PATH or startup files. The examples below use Bash, such as the Linux terminal in Ubuntu or WSL. PowerShell and other shells can give the same command names different meanings or options.


Use command -v to inspect the current result

command -v bash

This inspects the name bash; it does not start another Bash process. A result such as /usr/bin/bash identifies the path found in this environment. Replace bash with the name you need to investigate, such as curl or python3.

command -v does not always return an absolute file path. It can report the name of a builtin or function, or describe an alias when aliases are active. Read the result before treating the returned text as an executable pathname.

List matching candidates with type -a

type -a bash

Multiple matching executables on PATH can produce multiple lines. An environment might list both /usr/bin/bash and /bin/bash, but that does not establish that two different versions are installed. Links can make different paths refer to the same underlying file.

Bash’s type -a can report aliases, reserved words, functions, builtins, and executables. In an interactive shell, an alias or function can take precedence over a file on PATH. Non-interactive scripts normally have alias expansion disabled, so investigate the environment that actually runs the failing task when terminal and script results differ.

Tell builtins from external executables

type -t printf
type -a printf

If the first output is builtin, Bash recognizes printf as a shell builtin. The type -a output can also list an external executable such as /usr/bin/printf. Commands with the same name can support different options depending on whether the builtin or external implementation is used.

type -t output Meaning
builtin A Bash builtin
file An executable file found by the shell
function A shell function
alias An active alias
keyword A Bash reserved word

These categories describe the current shell’s view. Another terminal, user, or WSL distribution can have a different PATH or load different settings. Comparing results in the same environment as the affected task helps avoid changing unrelated configuration.

Branch on whether a name was found

if command -v curl >/dev/null 2>&1; then
  printf 'curl is available\n'
else
  printf 'curl was not found\n'
fi

The first message appears if curl is found; otherwise the second appears. The test discards descriptive output and checks the exit status, so it does not need to parse a path or explanatory text. This example does not make a network request with curl.

Finding a name does not establish that it is the version you intended, that a connection will succeed, or that a particular option is supported. A function or alias can also satisfy the lookup. Identify the candidate and its type first, then use the tool’s documented version check or the specific operation you need.

If a script is found but fails to run, checking CRLF, LF and the shebang can help with a separate cause. For files on a Windows drive in WSL, the WSL permissions and metadata checks explain another issue that finding the command alone does not resolve.

References

このブラウザからの自分のアクセスを解析から除外できます。