-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PS 7.2] operator && doesn't recognize exit #17122
Comments
Duplicate of #10967 |
well actually through the duplicate i found that in this way works: $host.Version | Where-Object {$_.Major -eq 7} && $(exit 1)
Major Minor Build Revision
----- ----- ----- --------
7 2 2 -1
[process exited with code 1 (0x00000001)] so, yes it could be more a design discusion rather than a bug. I am closing this ticket as i am not considering it a bug anymore, but rather it was my lack of knowledge in PS. :) |
What comes after && must be a valid as pipeline so if/while/do/switch/exit/return statements won't work - There's plenty at #10967 but if it doesn't work with the | it won't work with || or && I was about to post the $() solution but as I was typing your reply appeared You do realise that where-object successfully running includes returning nothing so the right hand side always runs in your example :-) |
yeah right. My example it was really too much Bash biased. in brief: But it could be also the case that I have still a lot to learn around PS. 😄 @jhoneill |
I'd use an if - anything which isn't null, 0, empty or $false will be treated as true. (So it's rare to need .count etc)
This will exit if the version is 5.0, 6.0, or 7.0 If it is something complicated I can put a pipeline in the ()
This pattern is quite common
and then
Exit as some strange behaviour have a look at the end of this which I wrote after someone I was talking to was going made working out why they didn't get an exit code back. https://jhoneill.github.io/powershell/2019/08/21/ExitThrowReturnEtc.html
|
Prerequisites
Steps to reproduce
Using PS 7.2
for eg running this 1 line script:
it will result in the following error output:
Expected behavior
Actual behavior
It doesn't recognize exit keyword
Error details
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: