-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Support Question
I was experimenting with the new && and || statement operators and they do not work like I would expect. A left hand side evaluation of $false is considered "succeed" in the chain operators.
Here is my specific use case where I ran into this issue:
Test-Path -Path $Path || return
I was exiting a function early when the file was missing. If the left side did not "succeed", I expected the right side to execute. That is not what happened.
Because of this unexpected behavior, I turned to the RFC0046-Chain-Operators document. I used the bash examples from the top of the document and translated them into PowerShell. The results did not match the inline description.
These two specific examples executed incorrectly (I replaced false with $false):
$false && echo 'Second success' # Executes only the left-hand command (false always "fails")
$false || echo 'Second success' # Executes both left-hand and right-hand commands
I have no background with bash so I was approaching this as a PowerShell user trying to do what felt intuitive. I expected the evaluation to work just like the if(...){...} statement when it came to "succeeded" or "not succeeded". This discrepancy will be a frequent source of confusion if it is left as implemented.