You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Seemingly-obscure ${<file path>} feature broken on Linux #25760
Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working Group
(I must note that searching the Issues page for "${" is either not possible or very difficult since there are no results, sorry if this happens to be a dupe!)
While reading the PowerShell Wikipedia page, I cane across a sentence that described a feature I have never seen documented:
Enclosing the path to a file in braces preceded by a dollar sign (as in ${C:\foo.txt}) creates a reference to the contents of the file. If it is used as an L-value, anything assigned to it will be written to the file. When used as an R-value, the contents of the file will be read. If an object is assigned, it is serialized before being stored.[citation needed]
This works on both Windows PowerShell and Core, but not on Core for Linux.
Steps to reproduce
On a Linux system, write
${/etc/profile}# (or any other file that exists)
Expected behavior
PS> ${/etc/profile}< contents of /etc/profile here... >
Actual behavior
PS> ${/etc/profile}< no output >
Error details
n/a
Environment data
Name Value
---------
PSVersion 7.5.1
PSEdition Core
GitCommitId 7.5.1
OS Debian GNU/Linux 12 (bookworm)
Platform Unix
PSCompatibleVersions {1.0,2.0,3.0,4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
[Update: ${/etc/profile} isn't actually an instance of namespace variable notation, but ${/:/etc/profile} would be; see below for a summary.]
The only workaround is to define a helper PS drive with, say, New-PSDrive RootDir FileSystem /, and then use that drive as the root, e.g. ${RootDir:/etc/profile}
That said, the usefulness of namespace variable notation with respect to file-system paths (the FileSystem provider) has always been limited by the need to use literal paths, which may explain why the feature was never fixed on Unix-like platforms.
Indeed, 237dmitry: by the logic of namespace variable notation, ${/:/etc/profile} should work, as mentioned in #3245 and as argued in detail in #2268 (comment) (a PowerShell drive spec is needed, and / is indeed the name of a PowerShell drive on Unix-like platforms, as you show).
Why / PSDrive is not working? But ${Temp:/file} is.
if I may add not to argue, but New-PSDrive RootDir FileSystem / created a drive called RootDir:, not /:, so you would have to do ${RootDir:/etc/environment}, not ${/:/etc/environment}. Doing Get-PSDrive / gets the drive for the "main" PSDrive, which is used unqualified (no :). / can't be used for a PSDrive name:
new-psDrive-name '/'-PSProvider FileSystem -Root '/'New-PSDrive: Cannot process the drive name because the drive name contains one or more of the following characters that are not valid: ; ~ / \ . :
edit: i think the reason this doesn't work is that Windows drive names like C: share the PS syntax for namespacing variables, but Unix systems use a single "drive" at /, which means that it does not get interpreted as a namespace variable to a filesystem, but instead as a literal variable name:
>${/etc/somewhere}=1>get-variable
Name Value
---------# < ... >? True
/etc/somewhere 1
^ ${/etc/somewhere}# < ... >
It follows from the description of the feature in the linked comment that the example used in the initial post, ${/etc/profile} is not an instance of namespace variable notation (it refers to a regular variable with the unusual name /etc/profile), because it lacks a PowerShell drive specification (e.g., C: on Windows, or Temp: on both Windows and Unix), i.e. a reference to a PowerShell drive (which on Windows includes native file-system drives) with an underlying provider that implements the System.Management.Automation.Provider.IContentCmdletProvider interface.
While / is the name of a built-in PowerShell drive on Unix-like platforms (referring to the file-system root), it cannot be used as such, because /: isn't recognized as a drive spec.: ${/:/etc/profile} fails, even though it should report the contents of /etc/profile; similarly, trying to reference a file with a relative path, relative to the current location of said drive, doesn't work either, e.g. ${/:file.txt}
The fact that PowerShell - sensibly - prevents defining custom drives with a name containing / shouldn't prevent referring to the special, built-in / drive by way of a drive spec. (/:)
A - cumbersome - workaround is to define a custom drive with a regular name, e.g. New-PSDrive RootDir FileSystem /, and use its name, e.g. ${RootDir:/etc/profile}
This workaround comes with a pitfall with respect to relative paths: Each PowerShell drive has its own current location, so a reference such as ${RootDrive:file.txt} would implicitly refer to a file file.txt in whatever the current location is on the RootDrive: drive, which is likely to differ from the one on the / "drive".
Given that this problem has been known since 2017 and no action was taken, none may ever be, possibly owing to the general limitations of namespace variable notation that are most noticeable with respect to the FileSystem provider:
Notable limitations are: support for literally specified paths only (even though they're interpreted as wildcard expressions), lack of control over the character encoding, references to non-existent or empty files evaluate to $null (whereas an otherwise equivalent Get-Content call yields the enumerable null, [System.Management.Automation.Internal.AutomationNull]::Value, which behaves differently as pipeline input and as input to a switch statement)
As for potential fixes:
Allowing /: as a drive spec in paths would fix the problem.
Alternatively - should that be considered too problematic (/: is technically a valid path on typical Unix file-systems, but then again so is function:, for instance) - or possibly complementarily, prefixing a file-system path with FileSystem:: (or, more fully, Microsoft.PowerShell.Core\FileSystem::) could be allowed in the context of namespace variable notation, e.g. ${FileSystem::/etc/profile}:
Notably, something like Get-Content FileSystem::/etc/profile already works.
Even Windows could benefit from this change, namely in the context of relative paths: currently, you must at least specify the target drive in order to use a path relative to that drive's current location, e.g. ${C:file.txt}. With the change implemented, you could more flexibly use ${FileSystem::file.txt} to target the current location of whatever drive PowerShell's current (file-system) location happens to be on.
Either way, the broken support on Unix-like platforms should at least be documented, though to do so meaningfully would first require documenting the feature itself properly, along the lines of creating a new conceptual help topic named, say, about_Namespace_Variable_Notation to be mentioned in and linked from about_Providers.
Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working Group
Activity
mklement0 commentedon Jul 16, 2025
Good point; the feature name is namespace variable notation, and the issue was first raised in 2017:
[Update:
${/etc/profile}isn't actually an instance of namespace variable notation, but${/:/etc/profile}would be; see below for a summary.]The only workaround is to define a helper PS drive with, say,
New-PSDrive RootDir FileSystem /, and then use that drive as the root, e.g.${RootDir:/etc/profile}That said, the usefulness of namespace variable notation with respect to file-system paths (the
FileSystemprovider) has always been limited by the need to use literal paths, which may explain why the feature was never fixed on Unix-like platforms.237dmitry commentedon Jul 16, 2025
Why
/PSDrive is not working? But${Temp:/file}is.mklement0 commentedon Jul 16, 2025
Indeed, 237dmitry: by the logic of namespace variable notation,
${/:/etc/profile}should work, as mentioned in #3245 and as argued in detail in #2268 (comment) (a PowerShell drive spec is needed, and/is indeed the name of a PowerShell drive on Unix-like platforms, as you show).237dmitry commentedon Jul 16, 2025
Of course, I tried it first.
mklement0 commentedon Jul 16, 2025
237dmitry commentedon Jul 16, 2025
Your comment nothing explained. It is important to understand why the same syntax does not work for different PSDrives
mklement0 commentedon Jul 16, 2025
helpimnotdrowning commentedon Jul 16, 2025
237dmitry,
if I may add not to argue, but
New-PSDrive RootDir FileSystem /created a drive calledRootDir:, not/:, so you would have to do${RootDir:/etc/environment}, not${/:/etc/environment}. DoingGet-PSDrive /gets the drive for the "main" PSDrive, which is used unqualified (no:)./can't be used for a PSDrive name:edit: i think the reason this doesn't work is that Windows drive names like
C:share the PS syntax for namespacing variables, but Unix systems use a single "drive" at/, which means that it does not get interpreted as a namespace variable to a filesystem, but instead as a literal variable name:237dmitry commentedon Jul 16, 2025
This is the good explanation, thank you.
mklement0 commentedon Jul 16, 2025
mklement0 commentedon Jul 17, 2025
Let me attempt a summary:
The semi-official name of the feature in question is namespace variable notation.
Variable assigment to files ignores all encoding settings and uses ... ASCII? #2268 (comment) provides an overview of the feature and its (dearth of) documentation.
It follows from the description of the feature in the linked comment that the example used in the initial post,
${/etc/profile}is not an instance of namespace variable notation (it refers to a regular variable with the unusual name/etc/profile), because it lacks a PowerShell drive specification (e.g.,C:on Windows, orTemp:on both Windows and Unix), i.e. a reference to a PowerShell drive (which on Windows includes native file-system drives) with an underlying provider that implements theSystem.Management.Automation.Provider.IContentCmdletProviderinterface.However, namespace variable notation is indeed broken on Unix-like platforms, as previously discussed in issues such as Namespace variable notation referencing the FileSystem provider is broken on Unix platforms #3245:
While
/is the name of a built-in PowerShell drive on Unix-like platforms (referring to the file-system root), it cannot be used as such, because/:isn't recognized as a drive spec.:${/:/etc/profile}fails, even though it should report the contents of/etc/profile; similarly, trying to reference a file with a relative path, relative to the current location of said drive, doesn't work either, e.g.${/:file.txt}/shouldn't prevent referring to the special, built-in/drive by way of a drive spec. (/:)A - cumbersome - workaround is to define a custom drive with a regular name, e.g.
New-PSDrive RootDir FileSystem /, and use its name, e.g.${RootDir:/etc/profile}${RootDrive:file.txt}would implicitly refer to a filefile.txtin whatever the current location is on theRootDrive:drive, which is likely to differ from the one on the/"drive".Given that this problem has been known since 2017 and no action was taken, none may ever be, possibly owing to the general limitations of namespace variable notation that are most noticeable with respect to the
FileSystemprovider:$null(whereas an otherwise equivalentGet-Contentcall yields the enumerable null,[System.Management.Automation.Internal.AutomationNull]::Value, which behaves differently as pipeline input and as input to aswitchstatement)As for potential fixes:
Allowing
/:as a drive spec in paths would fix the problem.Alternatively - should that be considered too problematic (
/:is technically a valid path on typical Unix file-systems, but then again so isfunction:, for instance) - or possibly complementarily, prefixing a file-system path withFileSystem::(or, more fully,Microsoft.PowerShell.Core\FileSystem::) could be allowed in the context of namespace variable notation, e.g.${FileSystem::/etc/profile}:Get-Content FileSystem::/etc/profilealready works.${C:file.txt}. With the change implemented, you could more flexibly use${FileSystem::file.txt}to target the current location of whatever drive PowerShell's current (file-system) location happens to be on.Either way, the broken support on Unix-like platforms should at least be documented, though to do so meaningfully would first require documenting the feature itself properly, along the lines of creating a new conceptual help topic named, say,
about_Namespace_Variable_Notationto be mentioned in and linked from about_Providers.