Title: get-childitem env: fails on Windows when an environment variable is defined twice, cased differently · Issue #6305 · PowerShell/PowerShell · GitHub
Open Graph Title: get-childitem env: fails on Windows when an environment variable is defined twice, cased differently · Issue #6305 · PowerShell/PowerShell
X Title: get-childitem env: fails on Windows when an environment variable is defined twice, cased differently · Issue #6305 · PowerShell/PowerShell
Description: The problem: get-childitem env: fails on Windows when an environment variable exists twice, each instance cased differently. The scenario: On Windows, set the environment variable NPM_CONFIG_PATH to control where the npm cache is created...
Open Graph Description: The problem: get-childitem env: fails on Windows when an environment variable exists twice, each instance cased differently. The scenario: On Windows, set the environment variable NPM_CONFIG_PATH t...
X Description: The problem: get-childitem env: fails on Windows when an environment variable exists twice, each instance cased differently. The scenario: On Windows, set the environment variable NPM_CONFIG_PATH t...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6305
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"get-childitem env: fails on Windows when an environment variable is defined twice, cased differently","articleBody":"The problem:\r\n`get-childitem env:` fails on Windows when an environment variable exists twice, each instance cased differently.\r\n\r\nThe scenario:\r\nOn Windows, set the environment variable `NPM_CONFIG_PATH` to control where the npm cache is created. And use npm to run unit tests, use powershell within a unit test, and from powershell invoke `get-childitem env:`. Note, it is common to use `npm test` to build and test a nodejs project.\r\n\r\nIt appears npm internally creates environment variables to manage state, and a lower-case variable `npm_config_path` is created. When powershell is invoked from the unit test, the environment variables `NPM_CONFIG_PATH` and `npm_config_path` are both set.\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\nOn Windows, tested with npm v5.6.0 in my PATH.\r\n\r\n```powershell\r\nWrite-Host \"******************** SETTING NPM_CONFIG_PATH ********************\"\r\n$null = mkdir env-test\r\ncd env-test\r\n$env:NPM_CONFIG_PATH = $PWD\r\nWrite-Host \"******************** CREATING PACKAGE.JSON ********************\"\r\n\u0026 npm init --force --yes\r\nWrite-Host \"******************** MODIFYING PACKAGE.JSON ********************\"\r\n$package = Get-Content package.json | ConvertFrom-Json\r\n$package.scripts.test = \"pwsh -command Get-ChildItem env:\"\r\nSet-Content -LiteralPath package.json -Encoding UTF8 -Value (ConvertTo-Json -InputObject $package -Depth 99)\r\nGet-Content package.json\r\nWrite-Host \"******************** TESTING ENV PS DRIVE, VIA NPM ********************\"\r\n\u0026 npm test\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nPowerShell should gracefully handle the duplicate environment variable. The `set` builtin in cmd.exe handles it gracefully. .NET `Environment.GetEnvironmentVariables()` handles it gracefully.\r\n\r\nActual behavior\r\n---------------\r\n\r\nGet-ChildItem fails with \\\"An item with the same key has already been added. Key: NPM_CONFIG_PATH\\\"\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\n\u003e $PSVersionTable\r\nName Value\r\n---- -----\r\nPSVersion 6.0.1\r\nPSEdition Core\r\nGitCommitId v6.0.1\r\nOS Microsoft Windows 10.0.16299\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n","author":{"url":"https://github.com/ericsciple","@type":"Person","name":"ericsciple"},"datePublished":"2018-03-03T01:55:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/6305/PowerShell/issues/6305"}
| 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:34609168-512d-34d1-417e-e6d9ea621e1a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD36:26822E:4D910D:6B8D55:6A551ECB |
| html-safe-nonce | 8147b21f794acfd014c5c162b94ba3c45391d3f71c57bb0ff414a77ebcf3140c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDM2OjI2ODIyRTo0RDkxMEQ6NkI4RDU1OjZBNTUxRUNCIiwidmlzaXRvcl9pZCI6IjQ3NDY1MzkxNDU2NzMxMjE0ODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 474c5540c5b470a0a2639b1ee64a40abdf0ea901c54bd593251b99b95b89de83 |
| hovercard-subject-tag | issue:301957108 |
| 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/6305/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1f485152e940b17407d97860bd4b8e10df09c0ba08c180bb640cdc2c433491ca/PowerShell/PowerShell/issues/6305 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f485152e940b17407d97860bd4b8e10df09c0ba08c180bb640cdc2c433491ca/PowerShell/PowerShell/issues/6305 |
| og:image:alt | The problem: get-childitem env: fails on Windows when an environment variable exists twice, each instance cased differently. The scenario: On Windows, set the environment variable NPM_CONFIG_PATH t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ericsciple |
| hostname | github.com |
| expected-hostname | github.com |
| None | 682d273eacb2ac51680c6eb9c0b270f029f7ce74c32090f319083c34497e28a5 |
| 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 | 358dd24ad7465d20e3fae729b5b169d35b0dd7f8 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width