Title: Suggestion: implement Bash-style && and || control operators for chaining commands based on success / failure - short-circuiting Boolean execution-flow control operators · Issue #3241 · PowerShell/PowerShell · GitHub
Open Graph Title: Suggestion: implement Bash-style && and || control operators for chaining commands based on success / failure - short-circuiting Boolean execution-flow control operators · Issue #3241 · PowerShell/PowerShell
X Title: Suggestion: implement Bash-style && and || control operators for chaining commands based on success / failure - short-circuiting Boolean execution-flow control operators · Issue #3241 · PowerShell/PowerShell
Description: Bash-style && and || control operators would be handy additions to the language. For instance, instead of writing (the examples are contrived, but hopefully illustrate the point): # If command A succeeds, execute command B too. csc /nolo...
Open Graph Description: Bash-style && and || control operators would be handy additions to the language. For instance, instead of writing (the examples are contrived, but hopefully illustrate the point): # If command A su...
X Description: Bash-style && and || control operators would be handy additions to the language. For instance, instead of writing (the examples are contrived, but hopefully illustrate the point): # If comm...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3241
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: implement Bash-style && and || control operators for chaining commands based on success / failure - short-circuiting Boolean execution-flow control operators","articleBody":"Bash-style `&&` and `||` control operators would be handy additions to the language.\r\n\r\nFor instance, instead of writing (the examples are contrived, but hopefully illustrate the point):\r\n\r\n```powershell\r\n# If command A succeeds, execute command B too.\r\ncsc /nologo file.cs\r\nif (0 -eq $LASTEXITCODE) { git commit -m 'ok' }\r\n\r\n# if command A fails, execute command B.\r\ncsc /nologo file.cs\r\nif (0 -ne $LASTEXITCODE) { git commit -m 'failed' }\r\n```\r\n\r\none might be able to write:\r\n\r\n```powershell\r\n# If command A succeeds, execute command B too.\r\ncsc /nologo file.cs && git commit -m 'ok'\r\n\r\n# if command A fails, execute command B.\r\ncsc /nologo file.cs || git commit -m 'failed'\r\n```\r\n\r\nThe examples use external utilities, but these operators would be equally handy for PowerShell-native commands (where `$?` rather than `$LASTEXITCODE` would have to be examined).\r\n\r\n---\r\n\r\n* There was [talk about adding `&&` and `||` in 2009](http://stackoverflow.com/a/573295/45375), but it seemingly never made the top of the list. Notably, @jpsnover himself said:\r\n\r\n> && and || were on the list of things to implement (still are) but did not pop up as the next most useful thing to add.\r\n \r\n* There is a [feature request on windowsserver.uservoice.com](https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11087898-implement-the-and-operators-that-bash-has) that seems to be languishing.\r\n\r\nThere are several other questions on Stack Overflow asking for this feature and I've tried to summarize the state of affairs in [this answer](http://stackoverflow.com/a/41816341/45375).\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-03-02T21:01:00Z","url":"https://github.com/PowerShell/PowerShell/issues/3241"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:71ec33b3-e2c9-4d04-d5f4-6c30868a73df |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB6A:1BB1CE:5FA98:819E0:6AFD48A8 |
| html-safe-nonce | 00e7b4a91f7ebde32e701b7952dc54e97b56c2243e941243a7b7bfe100b486fd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjZBOjFCQjFDRTo1RkE5ODo4MTlFMDo2QUZENDhBOCIsInZpc2l0b3JfaWQiOiIzMTkwMjUxOTMwNTkyODIzNDY0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4ee4ca47b4084601fdf65a7fb033dda2dfc28b78688d23ce6565627cfe7412ed |
| hovercard-subject-tag | issue:211516238 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/3241/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3d48c9fb98b69cb6e42b1b96ce4272d202d5be3912c76d07a2ecd9bf4dff87cb/PowerShell/PowerShell/issues/3241 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3d48c9fb98b69cb6e42b1b96ce4272d202d5be3912c76d07a2ecd9bf4dff87cb/PowerShell/PowerShell/issues/3241 |
| og:image:alt | Bash-style && and || control operators would be handy additions to the language. For instance, instead of writing (the examples are contrived, but hopefully illustrate the point): # If command A su... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | bdbacc25b921224ff0befcb9e629560a1255be51aec9991d6e3f95b5e9151474 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 556dd37bb0aceffb25724e151b5d858b3265b40b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width