Hans Wurst
Hans Wurst

Reputation: 384

Why does ($false || $true) evaluate to False in Powershell 7+?

In Powershell 7.2 Write-Output ($false || $true) will output False. Why?

Upvotes: 1

Views: 887

Answers (1)

TessellatingHeckler
TessellatingHeckler

Reputation: 29003

Because it's not "logical OR", that would be -or or -bor. It is doing "if the first command failed, run the second one".

Referencing the variable $false doesn't fail, so referencing the variable $true isn't executed.

For comparison, try asdfg || $true, if the command is not found, you get an error and then $true.

Upvotes: 4

Related Questions