Title: Unquoted strings · Issue #146 · PoshCode/PowerShellPracticeAndStyle · GitHub
Open Graph Title: Unquoted strings · Issue #146 · PoshCode/PowerShellPracticeAndStyle
X Title: Unquoted strings · Issue #146 · PoshCode/PowerShellPracticeAndStyle
Description: PowerShell allows for unquoted strings as shown in the Style-Guide/Naming-Conventions: # Instead write: Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath README.md) But there are limitations to using unquoted strings as e.g. sp...
Open Graph Description: PowerShell allows for unquoted strings as shown in the Style-Guide/Naming-Conventions: # Instead write: Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath README.md) But there are limitati...
X Description: PowerShell allows for unquoted strings as shown in the Style-Guide/Naming-Conventions: # Instead write: Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath README.md) But there are limitati...
Opengraph URL: https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/146
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unquoted strings","articleBody":"PowerShell allows for unquoted strings as shown in the [Style-Guide/Naming-Conventions](https://poshcode.gitbooks.io/powershell-practice-and-style/Style-Guide/Naming-Conventions.html):\r\n```PowerShell\r\n# Instead write:\r\nGet-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath README.md)\r\n```\r\n\r\nBut there are limitations to using unquoted strings as e.g. spaces are not allowed in an unquoted value and will obviously fail if not quoted (with either single or double quotes, see the related issue: #63):\r\n```PowerShell\r\n# Wrong:\r\nGet-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath READ ME.md)\r\n```\r\n\r\nBesides using unquoted strings in argument values, unquoted strings are common (best practice?) in hash tables keys. Hash tables are major objects in PowerShell along with PSCustomObjects which are in fact constructed from a hash table. Hash tables are also used for things like splatting and PowerShell Data files.\r\n\r\nAs with argument values, the use of unquoted hash table keys is limited to certain characters, as e.g.:\r\n```PowerShell\r\n# Wrong:\r\n$Options = @{\r\n Margin = 2\r\n Padding = 2\r\n Font-Size = 24\r\n}\r\n```\r\nWill cause an error:\r\n```\r\nLine |\r\n 4 | Font-Size = 24\r\n | ~\r\n | Missing '=' operator after key in hash literal.\r\n```\r\n\r\nIn some cases there are no errors but pitfalls, like:\r\n```PowerShell\r\n$Hashtable = @{ \r\n U2 = 'String'\r\n 2U = 'UInt32'\r\n}\r\n```\r\n```PowerShell\r\n$Hashtable.keys\r\n2\r\nU2\r\n```\r\n\r\nAFAIK, there is no clear definition of when I should use quoted keys (or argument values) or when I might not. In other words: which characters are allowed for unquoted strings (or: which characters are not allowed for unquoted strings)?\r\nIt is also not described in [About Quoting Rules](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7) or in [About Special Characters](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters?view=powershell-7)\r\n\u003csub\u003e(Assuming I am right, should I created a separate documentation issue at the [PowerShell Team](https://github.com/PowerShell/PowerShell/issues)?)\u003c/sub\u003e\r\n\r\nSo usually I use quotes on a trial-on-error bases or pro-actively on a better-safe-than-sorry bases. But that could cause some inconsistency in defining the best (readable) practice to resolve the above error:\r\n\r\n ```PowerShell\r\n$Options = @{\r\n Margin = 2\r\n Padding = 2\r\n 'Font-Size' = 24\r\n}\r\n```\r\nOr:\r\n ```PowerShell\r\n$Options = @{\r\n 'Margin' = 2\r\n 'Padding' = 2\r\n 'Font-Size' = 24\r\n}\r\n```\r\nI am especially concerned with this writing style / best practice issue because I am maintaining a [ConvertTo-Expression](https://github.com/iRon7/ConvertTo-Expression) script. Although the code might not follow the styling guidelines (yet), I am committed to follow them for the expression it outputs as much as possible.\r\nFor this project, I got the issue request: [Remove quotes in HashTables Keys when possible](https://github.com/iRon7/ConvertTo-Expression/issues/3) and looking for some documented guidance.","author":{"url":"https://github.com/iRon7","@type":"Person","name":"iRon7"},"datePublished":"2020-06-19T18:32:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/146/PowerShellPracticeAndStyle/issues/146"}
| 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:b86ab800-afff-7fa5-199e-7f078c87df22 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9EE4:2CD505:2CD4ABC:3E20C3C:6977B4C7 |
| html-safe-nonce | 5239b04903cbc615f4ffdf33a0e1c36c447f1b5de48f8c852b1547ce4e83f309 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUU0OjJDRDUwNToyQ0Q0QUJDOjNFMjBDM0M6Njk3N0I0QzciLCJ2aXNpdG9yX2lkIjoiNjE1MzY1NTc0NzA1ODU3ODYzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3ec21966980a9e22fd5d7df8c3d39446051a12afc47558bec176c60f6a1699fe |
| hovercard-subject-tag | issue:642154328 |
| 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/PoshCode/PowerShellPracticeAndStyle/146/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a68c42c0e13507e1a023759ec7a2f188470c487753f3b81943f0d0d96f0d68f/PoshCode/PowerShellPracticeAndStyle/issues/146 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a68c42c0e13507e1a023759ec7a2f188470c487753f3b81943f0d0d96f0d68f/PoshCode/PowerShellPracticeAndStyle/issues/146 |
| og:image:alt | PowerShell allows for unquoted strings as shown in the Style-Guide/Naming-Conventions: # Instead write: Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath README.md) But there are limitati... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iRon7 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 831218810e1b66a41a0626c8c15f7f47625846d9a7516c7f43cfc2c61effad83 |
| turbo-cache-control | no-preview |
| go-import | github.com/PoshCode/PowerShellPracticeAndStyle git https://github.com/PoshCode/PowerShellPracticeAndStyle.git |
| octolytics-dimension-user_id | 5641451 |
| octolytics-dimension-user_login | PoshCode |
| octolytics-dimension-repository_id | 17317123 |
| octolytics-dimension-repository_nwo | PoshCode/PowerShellPracticeAndStyle |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 17317123 |
| octolytics-dimension-repository_network_root_nwo | PoshCode/PowerShellPracticeAndStyle |
| 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 | b37ffa89d073c0d4a6f07ff42d59120741a74955 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width