Skip to content

about_Automatic_Variables should be updated to indicate that automatic variables that are conceptually read-only can still be assigned to, and that that won't change for most of them so as not to break existing code #1510

@mklement0

Description

@mklement0

From PowerShell/PowerShell#3061 (comment):

We discussed possibly making all automatic variables functionally read only, however, agreed that in many cases like $PWD someone could be using it already without problem as they didn't Set-Location so $PWD isn't overwritten. So other than $_, $PSItem, and $Input, we decided to error on the side of limiting the breaking change to the most common cases.

Therefore it should be noted in the documentation that other conceptually read-only variables, even though they can be written to - for backward compatibility - shouldn't be.

In PSv6, hopefully, a PSScriptAnalyzer rule will warn about doing so, but there's nothing in the engine that will enforce this.

Version(s) of document impacted

  • Impacts 6 document
  • Impacts 5.1 document
  • Impacts 5.0 document
  • Impacts 4.0 document
  • Impacts 3.0 document

Metadata

Metadata

Assignees

Labels

Pri2Priority - Medium

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions