which — Locate an executable in PATH and print its full path across all 5 shells
Equivalents in every shell
which python3External `/usr/bin/which` binary, not a bash builtin. Prints the first PATH match and exits 0; non-zero (often 1) when the command is not found.
which python3Zsh ships its own `which` builtin in addition to the external binary. The builtin behaves like `whence -c` and can also resolve aliases and functions.
which python3Fish uses the external `which` binary. For builtin-aware lookup prefer `type python3` instead.
Get-Command python3Aliased as `gcm`. Returns a `CommandInfo` object rather than plain text; read `.Source` (or `.Path` for `Application` types) to get just the path string.
where python3Built-in since Windows Server 2003 / Vista. `where` prints *all* PATH matches, not just the first — a key behavioural difference from Unix `which`.
Worked examples
Find where the python3 binary lives
which python3(Get-Command python3).Sourcewhere python3Test in a script whether a command exists
if which jq >/dev/null 2>&1; then echo yes; fiif which jq >/dev/null 2>&1; echo yes; endif (Get-Command jq -ErrorAction SilentlyContinue) { "yes" }where jq >nul 2>&1 && echo yesList every PATH match, not just the first
which -a python3Get-Command python3 -All | Select-Object -ExpandProperty Sourcewhere python3Gotchas
- `which` on Linux is GNU `which`; on macOS it is the BSD version. The BSD version does not accept `-a` on older systems — use `type -a` for builtin-aware multi-match listing.
- Bash `which` does NOT resolve aliases or shell functions because it is an external binary that knows nothing about your current shell. Use `type` (bash/zsh) or `command -v` for shell-aware lookup.
- PowerShell `Get-Command` returns an *object*. `Get-Command python3` prints a table; `.Source` is the bare path string. Piping to text-only consumers needs the explicit property.
- Windows `where` looks in PATH *and* the current directory. Unix `which` ignores the current directory unless `.` is in PATH (which is a security anti-pattern). Account for the difference when porting scripts.
- On bare Windows there is no `which.exe` — running `which` in cmd.exe or PowerShell errors out. Use `where` (cmd) or `Get-Command` (PowerShell), or rely on Git Bash / WSL for the Unix command.
WSL & PowerShell Core notes
Related glossary
Common tasks using which
- Detect the current shell
Determine which shell (bash / zsh / fish / pwsh / cmd) is currently running — for conditional dotfile loading and script-detection scenarios.
- Show the file path of a command
Print where on the filesystem a command resolves to — for debugging PATH issues, version mismatches, and "which python is this".