command -v silently reports every tool as missing
aliases · case
Affectspowershell 51, pwsh 7, windows
Fails assilent
Mechanismabsent builtin noop
Safe fixget command
Symptom
Section titled “Symptom”An agent (or a ported bash script) probes for a tool with command -v foo under
PowerShell. The probe prints nothing and the script concludes the tool is
missing — even though it is installed and on PATH. Installs get re-run,
bootstraps loop, “missing dependency” errors lie.
command -v git # prints nothing, no error, $? stays trueGet-Command git # works: CommandType Application, path shownPowerShell has no command builtin. Depending on parse context, command -v git
either matches nothing quietly or binds to unrelated tokens; it raises no error
and sets no useful exit state. The bash idiom fails in the WORST way: silently,
with a plausible-looking negative result.
Workaround
Section titled “Workaround”- Probe with
Get-Command <tool> -ErrorAction SilentlyContinue(null check) or simply run<tool> --versionand check$LASTEXITCODE. - Agent prompts targeting Windows must map
command -v→Get-Command; the referenced commit ships that rule as a documented shell-hazard contract.