René's URL Explorer Experiment


Title: Inconsistent, unpredictable behavior of "-"-prefixed barewords in argument mode · Issue #4624 · PowerShell/PowerShell · GitHub

Open Graph Title: Inconsistent, unpredictable behavior of "-"-prefixed barewords in argument mode · Issue #4624 · PowerShell/PowerShell

X Title: Inconsistent, unpredictable behavior of "-"-prefixed barewords in argument mode · Issue #4624 · PowerShell/PowerShell

Description: Follow-up to #4576 and #4591 Context: Note: By bareword I mean a run of non-whitespace characters not single- or double-quoted as a whole (e.g., foo), used in argument mode, and normally interpreted as an expandable string (e.g., $HOME/b...

Open Graph Description: Follow-up to #4576 and #4591 Context: Note: By bareword I mean a run of non-whitespace characters not single- or double-quoted as a whole (e.g., foo), used in argument mode, and normally interprete...

X Description: Follow-up to #4576 and #4591 Context: Note: By bareword I mean a run of non-whitespace characters not single- or double-quoted as a whole (e.g., foo), used in argument mode, and normally interprete...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4624

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent, unpredictable behavior of \"-\"-prefixed barewords in argument mode","articleBody":"\u003csup>Follow-up to #4576 and #4591\u003c/sup>\r\n\r\n### Context:\r\n\r\nNote: By _bareword_ I mean a run of non-whitespace characters not single- or double-quoted as a whole (e.g., `foo`), used in argument mode, and normally interpreted as an expandable string (e.g., `$HOME/boy`).\r\n\r\nWhile `-`-prefixed barewords _look_ like _parameter names_ (e.g.,`-foo`), they _sometimes_ act as _arguments_ (_values_ to bind to parameters), and the ability to use them as such is important in two contexts:\r\n\r\n* In the context of the external CLI, when passing the name of a script file that happens to start with `-`; e.g., `powershell -File -foo.ps1`\r\n\r\n* When passing arguments _through_ that themselves happen to be command line or command-line fragments, which is enabled by cmdlets/advanced functions that declare a `ValueFromRemainingArguments` parameter; e.g., \r\n`Get-Command -Syntax Get-ChildItem -Path cert:` passes `-Path cert:` through (the `-Path` bareword is _not_ interpreted as `Get-Command`'s parameter) in order to discover the certificate provider's dynamic parameters.\r\n\r\nNote that, except when using the external CLI, you can always use _quoting_ to explicitly mark a bareword as an _argument_.\r\n\r\nGenerally, though, if there's no ambiguity, not having to quote tokens that don't strictly need it is a matter of convenience.\r\n\r\n### The problem:\r\n\r\nThere are two major problems with how `-`-prefixed barewords are currently parsed and interpreted:\r\n\r\n* Pragmatically speaking, **their syntactic role (parameter name vs. argument) is virtually unpredictable by the end user**. \r\n\r\n   * E.g., the `-a` in `Get-Item -LiteralPath -a` is an _argument_, whereas the `-c` in `Get-Item -LiteralPath -c` is _parameter name_`-Credential`.\r\n\r\n* They are **not parsed and expanded in the same way as barewords that do _not_ start with `-`**.\r\n\r\n   * E.g., bareword `a$HOME` expands `$HOME`, while `-a$HOME` does not.\r\n\r\nMore examples below.\r\n\r\n### Solution options:\r\n\r\n* Leave things as they are and _document_ the current behavior, recommending that _quoting_ be used for predictability.\r\n\r\n* Change the parameter binding as proposed in #4576: Once a parameter has been (unambiguously) identified, its specific definition  - switch vs. parameter-with-argument- _alone_ determines whether the next token is its argument or a different parameter:\r\n\r\n  * E.g., in `Get-Item -LiteralPath -p`, `-p` would _unambiguously_ be an _argument_, because `-LiteralPath` _syntactically requires_ an argument.\r\n\r\n    * An argument can be made that in cases where the _user intent_ was likely different - e.g., `Get-Item -LiteralPath -Path` - that _unconditional_ interpretation of `-`-prefixed barewords as _parameter names_ is preferable in terms of the user experience (`Missing an argument for parameter 'LiteralPath'` as opposed to `Cannot find path '-Path' because it does not exist`); a point that [@markekraus has made](https://github.com/PowerShell/PowerShell/issues/4576#issuecomment-322574632).\r\n\r\n     * That said, I think the conceptual simplicity and clarity of the let-the-identified-parameter-determine-the-next-token's-syntactic-role approach is more beneficial in the grand scheme of things.\r\n\r\n  * Note: [@lzybkr has already discounted this option](https://github.com/PowerShell/PowerShell/issues/4576#issuecomment-322572999) based on implementation cost, but I'm resubmitting it for consideration now that we have a fuller picture of all the issues involved: \r\n>  I can't see adding more complexity to the parameter binder to change this behavior.\r\n\r\n\r\n* Disallow `-`-prefixed barewords altogether, as proposed in #4591: In order for a `-`-prefixed tokens to be recognized as an _argument_, it would have to be _single- or double-quoted_ .\r\n\r\n   * E.g., `Get-Item -LiteralPath -a` would then _break_, because `Get-Item` has no `-a*` parameter, and `Get-Item -LiteralPath '-a'` would have to used consistently. (But, in contrast, PowerShell's _outside_ CLI would still need to accept something like `-File -a`.)\r\n\r\n   * The convenience of being able to specify `-`-prefixed tokens _as arguments_ is lost, but at least the behavior is _predictable_.\r\n\r\n     * That said, the waters would still be muddy with respect to commands that have a `ValueFromRemainingArguments` parameter, where, based on the current behavior, a `-`-prefixed barewords _if it happens not to match a regular parameter_ would still be interpreted as an _argument_.\r\n\r\n### Examples:\r\n\r\n```powershell\r\n### Virtually unpredictable syntactic role\r\n\r\n# BREAKS\r\n# -c, because it happens to match parameter name -Credential, is interpreted as a *parameter name*.\r\n# Note that, purely based on -LiteralPath being a parameter that *requires an argument*, there is\r\n# no good reason to parse -c as a parameter name. The syntax of Get-Item unambigously implies that\r\n# the token following -LiteralPath must be an *argument*.\r\nGet-Item -LiteralPath -c\r\n\r\n# SUCCEEDS\r\n# -a, because it happens not to match any of Get-Item's parameters, is interpreted as an *argument*\r\nGet-Item -LiteralPath -a\r\n\r\n\r\n# Even though a \"-\"-prefixed token as the 1st argument is normally *invariably* interpreted as \r\n# a *parameter name*, that is not the case for cmdlets with a ValueFromRemainingArguments parameter,\r\n# such as Write-Output:\r\n\r\n# BREAKS\r\n# -n happens to match parameter (switch) -NoEnumeration, and the call is therefore missing\r\n# arguments to output (-InputObject)\r\nWrite-Output -n\r\n# Solution: Use -- to signal the start of all positional arguments.\r\nWrite-Output -- -n\r\n\r\n# SUCCEEDS, because -z happens not to match a parameter name and is therefore bound to -InputObject.\r\nWrite-Output -z\r\n\r\n### Parsing / expansion inconsistencies\r\n\r\n# As part of an array, a \"-\"-prefixed bareword doesn't work as the 1st element.\r\nWrite-Output -a, b\t# BREAKS\r\nWrite-Output a, -b  # SUCCEEDS\r\n\r\n\r\n# \"-\"-prefixed barewords are non-expanding\r\nWrite-Output a$HOME   # expands $HOME\r\nWrite-Output -a$HOME  # doesn't expand $HOME\r\n\r\n\r\n# A \"-\"-prefixed bareword containing a \".\"-prefixed suffix is parsed as *2* arguments\r\nGet-Item -LiteralPath a.ps1  # SUCCEEDS\r\nGet-Item -LiteralPath -a.ps1 # BREAKS: Get-Item receives *2* arguments: '-a' and '.ps1'\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-beta.5 on macOS 10.12.6\r\nPowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS\r\nPowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-08-20T16:40:15Z","url":"https://github.com/PowerShell/PowerShell/issues/4624"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f8a2ec22-58f4-14da-e1b3-8acfa12763db
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8012:11BFC:285E003:384D612:6AFD52D0
html-safe-nonceeb18d0e6f8b9f76050e18ca059b064dde039aa3650a8b0e5b511e85dc939b195
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDEyOjExQkZDOjI4NUUwMDM6Mzg0RDYxMjo2QUZENTJEMCIsInZpc2l0b3JfaWQiOiIxMzM3NDg5MzA3ODExNTMzNTIwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac766a16f5ff167ba7d9ead3ee04bbde78a6689c14e9bfb7c21cce01340f2b8b85
hovercard-subject-tagissue:251499818
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/4624/issue_layout
twitter:imagehttps://opengraph.githubassets.com/dbce60dc286c01d928380eddcfe79613878163a812ff7c50752fe629c0e320cc/PowerShell/PowerShell/issues/4624
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/dbce60dc286c01d928380eddcfe79613878163a812ff7c50752fe629c0e320cc/PowerShell/PowerShell/issues/4624
og:image:altFollow-up to #4576 and #4591 Context: Note: By bareword I mean a run of non-whitespace characters not single- or double-quoted as a whole (e.g., foo), used in argument mode, and normally interprete...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemklement0
hostnamegithub.com
expected-hostnamegithub.com
None66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseb6f01f7cb9f35f8c09949773241a3d49dd04b340
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/PowerShell/PowerShell/issues/4624#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F4624
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F4624
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://github.com/PowerShell/PowerShell/issues/4624
Reloadhttps://github.com/PowerShell/PowerShell/issues/4624
Reloadhttps://github.com/PowerShell/PowerShell/issues/4624
PowerShellhttps://github.com/PowerShell
PowerShellhttps://github.com/PowerShell/PowerShell
Codehttps://github.com/PowerShell/PowerShell
Issues1.3k (1.3k)https://github.com/PowerShell/PowerShell/issues
Pull requests365 (365)https://github.com/PowerShell/PowerShell/pulls
Discussionshttps://github.com/PowerShell/PowerShell/discussions
Actionshttps://github.com/PowerShell/PowerShell/actions
Projectshttps://github.com/PowerShell/PowerShell/projects
Security and quality3 (3)https://github.com/PowerShell/PowerShell/security
Insightshttps://github.com/PowerShell/PowerShell/insights
https://github.com/PowerShell/PowerShell
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/4624
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/4624
Inconsistent, unpredictable behavior of "-"-prefixed barewords in argument modehttps://github.com/PowerShell/PowerShell/issues/4624#top
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Discussion%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Languageparser, language semanticshttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Language%22
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Aug 20, 2017https://github.com/PowerShell/PowerShell/issues/4624#issue-251499818
#4576https://github.com/PowerShell/PowerShell/issues/4576
#4591https://github.com/PowerShell/PowerShell/issues/4591
Parameter values disambiguated with their explicit parameter names should not require quoting #4576https://github.com/PowerShell/PowerShell/issues/4576
@markekraus has madehttps://github.com/PowerShell/PowerShell/issues/4576#issuecomment-322574632
@lzybkr has already discounted this optionhttps://github.com/PowerShell/PowerShell/issues/4576#issuecomment-322572999
"-"-prefixed barewords in argument mode should always be interpreted as parameter names #4591https://github.com/PowerShell/PowerShell/issues/4591
https://github.com/markekraus
Mark Kraus (markekraus)https://github.com/markekraus
on Aug 20, 2017https://github.com/PowerShell/PowerShell/issues/4624#issuecomment-323598863
Michael Klement (@mklement0)https://github.com/mklement0
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Aug 20, 2017https://github.com/PowerShell/PowerShell/issues/4624#issuecomment-323604452
Mark Kraus (@markekraus)https://github.com/markekraus
#4024 (comment)https://github.com/PowerShell/PowerShell/issues/4024#issuecomment-312267611
Ilya (iSazonov)https://github.com/iSazonov
WG-Languageparser, language semanticshttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Language%22
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Discussion%22
on Aug 21, 2017https://github.com/PowerShell/PowerShell/issues/4624#event-1213521528
https://github.com/apps/microsoft-github-policy-service
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
on Nov 16, 2023https://github.com/PowerShell/PowerShell/issues/4624#issuecomment-1814062066
Microsoft GitHub Policy Servicehttps://aka.ms/1es-gitops
https://github.com/apps/microsoft-github-policy-service
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
on Nov 16, 2023https://github.com/PowerShell/PowerShell/issues/4624#issuecomment-1814062071
Microsoft GitHub Policy Servicehttps://aka.ms/1es-gitops
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
on Nov 16, 2023https://github.com/PowerShell/PowerShell/issues/4624#event-10977935881
https://github.com/apps/microsoft-github-policy-service
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
on Nov 16, 2023https://github.com/PowerShell/PowerShell/issues/4624#issuecomment-1814070659
Microsoft GitHub Policy Servicehttps://aka.ms/1es-gitops
https://github.com/apps/microsoft-github-policy-service
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
on Nov 23, 2023https://github.com/PowerShell/PowerShell/issues/4624#issuecomment-1824451467
Microsoft GitHub Policy Servicehttps://aka.ms/1es-gitops
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
completedhttps://github.com/PowerShell/PowerShell/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Nov 23, 2023https://github.com/PowerShell/PowerShell/issues/4624#event-11047826068
Sign up for freehttps://github.com/signup?return_to=https://github.com/PowerShell/PowerShell/issues/4624
Sign in to commenthttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/4624
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Discussion%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Languageparser, language semanticshttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Language%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.