Skip to content

Enable backslash as alternative path delimiter #570

Closed

Description

@vors

Windows PowerShell allows both \ and / be path delimiters.

Consider

#  Full PS on Windows
PS C:\> 'foo' > bar
PS C:\> cat ./bar
foo
PS C:\> cat .\bar
foo

Versus

# Linux version
PSL /Users/vors/dev/PowerShell-Linux> 'foo' > bar
PSL /Users/vors/dev/PowerShell-Linux> cat ./bar
foo
PSL /Users/vors/dev/PowerShell-Linux> cat .\bar
cat : Cannot find path '/Users/vors/dev/PowerShell-Linux/.\bar' because it does not exist.

It's a problem for porting: there are scripts that could run as-is, but don't because of the wrong path delimiters.

On the other hand, on Linux you can create a folder foo\bar, so adding \ as alternative path separator would make this corner case harder.

This problem can be solved with additional escaping

cd foo`\bar

Sidenote: 'Set-Location' (cd) currently fails for it, but Get-ChildItem (ls) works

PSL /Users/vors/dev/PowerShell-Linux> ls ./foo\bar/


    Directory: /Users/vors/dev/PowerShell-Linux/foo\bar


Mode                LastWriteTime         Length Name                                                                                                                    
----                -------------         ------ ----                                                                                                                    
------          2/20/16   9:38 PM              6 1   


PSL /Users/vors/dev/PowerShell-Linux> cd ./foo\bar/
cd : An object at the specified path /Users/vors/dev/PowerShell-Linux/foo\bar does not exist.

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    Usability(LEGACY) Helps filter issues that might be higher priority because they directly affect usability
    on Feb 21, 2016
  2. andyleejordan commented on Feb 21, 2016

    @andyleejordan
    Member

    I'll note that the original developer and PM both preferred not supporting backslash, for various reasons that I can dig up if you wish.

    However, I support mapping backslash to slash and using PowerShell's escape character, backtick, to escape a backslash that is needed in an actual path name. But there is a LOT of code that deals with this, all of which would need to be fixed, and would likely better be a task for the PowerShell teams once we're on a unified code base.

  3. palladia commented on Feb 21, 2016

    @palladia
    Contributor

    Linux allows backslash as a valid character in file and directory names. Allowing it to be a directory separator would make things complicated. But interestingly, .NET supports both: altDirectorySeparatorChar

    Even on Windows, the mixing of forward and backward slashes isn't as perfect as it could be. We've had to modify many scripts and use Join-Path instead of hard-coded slashes.

  4. zach-folwick commented on Feb 22, 2016

    @zach-folwick
    Contributor

    sergei (@vors) "foo\bar" is a valid filename in *nix. It's also used for directories with spaces; e.g., "Program Files (x86)" would be "Program\ Files\ (x86)".

  5. vors commented on Feb 22, 2016

    @vors
    CollaboratorAuthor

    Zach Folwick (@zach-folwick) yes, I proposed tick for escaping them in names. For spaces escaping in PS somebody could use quotes around the name, instead of \ on every space.

  6. andyleejordan commented on Mar 1, 2016

    @andyleejordan
    Member

    From James Truher (@JamesWTruher)

    for example this should probably work:
    . $HOME/.powershell\profile.ps1

    new-item $HOME/.powershell\foo
    creates a file ".powershell\foo" in the HOME directory rather than a file "foo" in the $HOME/.powershell directory (additionally, it seems I can't remove this file from within powershell)

    As "" is a valid filesystem character, it may be that those paths need to be escaped in some way, but we need to do something - our current users use "" or "/" indiscriminately

  7. andyleejordan commented on Mar 1, 2016

    @andyleejordan
    Member

    I am all for reversing the previous decision to make PowerShell on Linux not slash agnostic. Can we do this John W. Fawcett (@FawcettJohnW), Paul Allen (@paulcallen)?

  8. andyleejordan commented on Mar 1, 2016

    @andyleejordan
    Member

    AFAICT we would need to add support for \ escaping the backslash, but once we had that, we could then just interpret unescaped backslashes asDirectorySeparatorChar`.

  9. FawcettJohnW commented on Mar 1, 2016

    @FawcettJohnW

    If I understand the proposal correctly, we would, for Linux, change all \ to /, unless it's escaped. If the user wants xxx\yyy, they can do xxx'\yyy and move forward. Is that correct? If so, it is consistent with other shells and I'm fine with it.

  10. JamesWTruher commented on Mar 1, 2016

    @JamesWTruher
    Collaborator

    I think we normalize to "/", but allow "". If a user wants a file with a "" in it, they escape it with `\

    j

  11. FawcettJohnW commented on Mar 1, 2016

    @FawcettJohnW

    Yep, sounds good to me.

    John

  12. andyleejordan commented on Mar 1, 2016

    @andyleejordan
    Member

    Great, this is a go. Editing title and labels.

  13. changed the title [-]Should backslash be the alternative path delimiter?[/-] [+]Enable backslash as alternative path delimiter[/+] on Mar 1, 2016
  14. 7 remaining items

  15. added
    Issue-BugIssue has been identified as a bug in the product
    and removed
    Issue-Enhancementthe issue is more of a feature request than a bug
    on May 5, 2016
  16. modified the milestones: , v0.5.0 on May 18, 2016
  17. andyleejordan commented on May 19, 2016

    @andyleejordan
    Member

    James Truher (@JamesWTruher) sergei (@vors) I think we can at least start with reverting the changes that were made to get us here in the first place, and then work from there to ensure backslashes as valid characters are fully supported via escaping. I'm probably more familiar with the original changes than anyone else, shall I take this on?

  18. joeyaiello commented on May 19, 2016

    @joeyaiello
    Contributor

    Let me ask a more general question: can we track/tag all the changes that need to be made in some way so that if we receive strong user feedback to reverse the decision, we easily can?

  19. andyleejordan commented on May 19, 2016

    @andyleejordan
    Member

    Well, yes. They'll be in Git.

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

Metadata

Metadata

Labels

Issue-BugIssue has been identified as a bug in the productUsability(LEGACY) Helps filter issues that might be higher priority because they directly affect usability

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions