Title: Align PowerShell's CLI / startup behavior with POSIX-like shells such as Bash - command-line arguments · Issue #3743 · PowerShell/PowerShell · GitHub
Open Graph Title: Align PowerShell's CLI / startup behavior with POSIX-like shells such as Bash - command-line arguments · Issue #3743 · PowerShell/PowerShell
X Title: Align PowerShell's CLI / startup behavior with POSIX-like shells such as Bash - command-line arguments · Issue #3743 · PowerShell/PowerShell
Description: This is a follow-up to #3600. To make PowerShell fit into the world of POSIX-like shells on Unix platforms, so that it can be a viable alternative, it must: support certain command-line parameters (options) exhibit certain default behavi...
Open Graph Description: This is a follow-up to #3600. To make PowerShell fit into the world of POSIX-like shells on Unix platforms, so that it can be a viable alternative, it must: support certain command-line parameters ...
X Description: This is a follow-up to #3600. To make PowerShell fit into the world of POSIX-like shells on Unix platforms, so that it can be a viable alternative, it must: support certain command-line parameters ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3743
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Align PowerShell's CLI / startup behavior with POSIX-like shells such as Bash - command-line arguments","articleBody":"\u003csup>This is a follow-up to #3600.\u003c/sup>\r\n\r\nTo make PowerShell fit into the world of POSIX-like shells on Unix platforms, so that it can be a viable alternative, it must: \r\n* support certain command-line parameters (options) \r\n* exhibit certain default behaviors on startup\r\n\r\nThe [POSIX spec for the `sh` utility](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html) prescribes both.\r\n\r\nDefinitely not everything there is applicable to PowerShell, but I think it's important to at least fundamentally exhibit the same behavior and to document to what extent PowerShell is compliant.\r\n\r\nA step has been made in the right direction by adding support for `-i` to start an interactive session - see #3558 \r\n\r\nMore work is needed, _some of which would result in breaking changes_.\r\n\r\nThe list is not complete, but hopefully covers the most important aspects.\r\n\r\n* POSIX-like shells default to _not_ loading any initialization files _when commands are passed_ (whether via stdin or via `-c`), whereas PowerShell _always_ loads its profiles, the only exception being explicit suppression with `-NoProfile`.\r\n\r\n * The POSIX behavior is the more sensible default: it makes for a more predictable execution environment and doesn't incur the cost of sourcing the initialization files.\r\n * Aligning PowerShell with this behavior would be a _breaking change_.\r\n * Arguably, when commands are combined with `-NoExit`, the profiles should still be loaded by default (note that this ability to execute commands on startup _and_ keep the shell open for interactive use is unique to PowerShell: POSIX-like shells invariably _exit_ after executing commands).\r\n * See #992, which has a [green-lit, but never-implemented committee decision](https://github.com/PowerShell/PowerShell/issues/992#issuecomment-384455760) to implement a _separate_ CLI entry point that doesn't load profiles, `pwsh-np`\r\n\r\n* PowerShell already reads commands from stdin by default, and also when `-Command -` (which arguably should be `-File -`) is specified, but:\r\n * `-s` is the POSIX option for explicitly specifying standard input, and should be supported too.\r\n * `-s` allows combining stdin command input with passing _parameters_, which PowerShell doesn't support; for instance, `bash` supports something like: \r\n`echo 'echo \"$# params\"' | bash -s one two`, which yields `2 params`.\r\n\r\n* `-Command` and `-File` issues:\r\n * They exhibit problematic interactive shell-like behaviors (with or without `-NonInteractive`) and lack consistent argument support - see #3223.\r\n\r\n * The way `-Command` currently parses the remaining arguments is problematic in itself and also fundamentally incompatible with POSIX-like shells - see https://github.com/PowerShell/PowerShell/issues/4024#issuecomment-311541803\r\n\r\n * [x] [Fixed by #4178] `-File` currently makes it impossible to pass Boolean values - see #4036.\r\n\r\n* [_This is already the case_] ~~`-c` must be locked in as an alias for `-Command`, so that future additions of -c* parameters don't break `-c` due to ambiguity.~~\r\n\r\n* `-i` works now, but no error occurs when it is combined with `-NonInteractive`, even though they directly contradict each other.\r\n * Note that starting a POSIX-like shell _without operands_ in a _terminal_ (with stdin and stderr connected to a terminal) _implies_ `-i` (and therefore loading of the initialization files).\r\n * Note that `-NonInteractive` doesn't prevent an interactive session per se, only in-session interactive features such as `Read-Host` and confirmation prompts.\r\n\r\n* [x] [Fixed by #9528] `-l` should be supported and trigger loading of the profiles - see #3600 for background.\r\n * `-l` is not part of POSIX, but supported by all major POSIX-like shells (`bash`, `dash`, `ksh`, and `zsh`)\r\n * `-l` is for creating a _login_ shell - which some platforms use by default (macOS); on Unix, only special contexts such as `ssh` sessions use them routinely.\r\n * Login shells load a separate set of initialization files compared to interactive non-login shells, but PowerShell has no distinction between login and non-login shells.\r\n * See https://github.com/PowerShell/PowerShell-RFC/pull/171/files for proposed changes to make PowerShell behave more like POSIX-like login shells.\r\n\r\n* [x] [Implemented with #4019] Passing a _positional argument_ should be interpreted as the _filename of a script to execute_ rather than a _shell command_.\r\n\r\n * In PowerShell terms: A positional argument should bind to `-File`, not `-Command` - this would be a breaking change, but would facilitate proper handling of shebang lines - see #3963\r\n\r\n * Conversely, to pass arbitrary shell commands, explicit use of `-Command` / `-c` should be required.\r\n\r\nCurrent as of PowerShell 7.3.1\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-05-09T15:00:37Z","url":"https://github.com/PowerShell/PowerShell/issues/3743"}
| 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:06674264-0691-40fc-6810-44bcf24b59a5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD5E:31688C:99A17:D1494:6AFD3DFD |
| html-safe-nonce | c429d813945286c20defddfc5bc4d75150149de109d51b83a5d7dd191af69460 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDVFOjMxNjg4Qzo5OUExNzpEMTQ5NDo2QUZEM0RGRCIsInZpc2l0b3JfaWQiOiI5MDE1NjY1MTkxMTI3MTcwNTU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e2c551a65dac1dbef2039e184147948ce1713127b3067726beec17f9b13fb4f1 |
| hovercard-subject-tag | issue:227396298 |
| 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/3743/issue_layout |
| twitter:image | https://opengraph.githubassets.com/55bb0c30f860a5f91873b38000e0eea9f5fed9209ef955b63ef9bd7b797e3534/PowerShell/PowerShell/issues/3743 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/55bb0c30f860a5f91873b38000e0eea9f5fed9209ef955b63ef9bd7b797e3534/PowerShell/PowerShell/issues/3743 |
| og:image:alt | This is a follow-up to #3600. To make PowerShell fit into the world of POSIX-like shells on Unix platforms, so that it can be a viable alternative, it must: support certain command-line parameters ... |
| 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