Skip to content

Namespace variable notation referencing the FileSystem provider is broken on Unix platforms #3245

Closed

Description

Steps to reproduce

Set-Location $HOME
${/:foo.txt} = 'hi, mom'
Get-Content foo.txt

Expected behavior

hi, mom

Actual behavior

The 2nd line causes the following error:

Access to the path '/:foo.txt' is denied.
....

Please see this explanation for why ${/:foo.txt} = 'hi, mom' - whose Windows equivalent is ${c:foo.txt} = 'hi, mom' - should work.

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.16) on Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64

Activity

  1. changed the title [-]Namespace variable notation is broken on Unix platforms[/-] [+]Namespace variable notation referencing the FileSystem provider is broken on Unix platforms[/+] on Mar 3, 2017
  2. BrucePay commented on Mar 4, 2017

    @BrucePay
    Collaborator

    Namespace notation does work but not when using "/:" as the drive. If you create a new drive named 'root'
    New-PSDrive -PSProvider filesystem -root / -scope global -name root:
    Then cd into that drive
    cd "root:$home"
    doing
    ${root:foo.txt} = 'hi, mom'
    Get-Content foo.txt
    works fine.

    In fact you can't use '/:' as a drive anywhere. For example, resolve-path /: fails with path not found whereas resolve-path root: works fine. This appears to be the real issue - that you can't use '/' as a drive name in paths.

  3. added
    Issue-Bug
    on Mar 4, 2017
  4. SteveL-MSFT commented on Mar 5, 2017

    @SteveL-MSFT
    Member

    The FileSystem provider explicitly disallows it:

    PS /home/steve> New-PSDrive -Root / -PSProvider FileSystem -Name /:                
    New-PSDrive : Cannot process the drive name because the drive name contains one 
    or more of the following characters that are not valid: ; ~ / \ . :
    At line:1 char:1
    + New-PSDrive -Root / -PSProvider FileSystem -Name /:
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-PSDrive], PSArgumentExcep 
       tion
        + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.NewPSDriveCo 
       mmand

    Should we support this? Perhaps the solution is to simply have root: defined as / on Linux systems.

  5. added
    WG-Engine-Providers
    Issue-Discussion
    and removed
    Issue-Bug
    on Mar 5, 2017
  6. iSazonov commented on Oct 8, 2017

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) We had related PRs - could you please re-check the Issue?

  7. mklement0 commented on Sep 16, 2018

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov): Sorry, I just realized that I never responded:

    It is still broken as of v6.1.0

  8. msftrncs commented on Mar 30, 2019

    @msftrncs
    Contributor

    Still doesn't work as of 6.2. Is the '/' drive merely a requirement internal to powershell so that it lists the filesystem provider in the drives list? While I understand that this would be a weird concept to Linux people to use something like dir /:., the fact it is listed (by get-psdrive) would make me think it should at least work, even though its not needed in that example.

  9. danielzgtg commented on Jun 22, 2023

    @danielzgtg

    Same on 7.3.4. This seems to be related to the differences with cd / on Windows and non-Windows platforms. cd alias: cd / leaves one at alias: on Windows, but the rootfs on non-Windows.

    Following this pattern on non-Windows, I propose a simpler syntax. How about we make ${/a/b/c} on non-Windows like ${c:\a\b\c} on Windows, and on Windows keep the old behavior of resolving to ${variable:/a/b/c}. This will only change strange scripts that name variables with leading slashes and make PowerShell more consistent across platforms.

  10. added
    Resolution-No Activity
    on Dec 20, 2023
  11. microsoft-github-policy-service commented on Dec 20, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-DiscussionResolution-No ActivityWG-Engine-Providers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions