Home > Net >  Why does ($false || $true) evaluate to False in Powershell 7 ?
Why does ($false || $true) evaluate to False in Powershell 7 ?

Time:12-04

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

CodePudding user response:

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.

  • Related