question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set-Location \ behaviour inconsistent between operating systems

See original GitHub issue

Prerequisites

Steps to reproduce

In #18308 we found that running cd\ will do different things depending on the operating system.

Steps:

  1. Navigate to any directory above your drive’s root level. > Set-Location Drive:/LizardPhotos/Skinks
  2. Run Set-Location \ or cd\
  3. You should now be at your drive’s root on windows, or your filesystem root on Linux & Mac.

Expected behavior

Windows, Mac, and Linux set location as the root of the current drive on`cd\`

Actual behavior

Windows sets location to the root of the current drive.
Mac and Linux sets location to the filesystem root.

Error details

N/A

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0-preview.9
PSEdition                      Core
GitCommitId                    7.3.0-preview.9
OS                             Microsoft Wind…
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0…
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image image image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jhoneillcommented, Oct 20, 2022

Programmatically, you can use the following to switch to the root of the current drive, on all platforms (which would obviously be too cumbersome interactively):

  • Set-Location ($PWD.Path -replace '(?<=[\\/]).*')

Since some of us already redefine CD to be something other than an alias for set location, that could be incorporated into a CD function.

/ is defined as a PS Drive on linux to ensure that cd / does in PowerShell what it does in other unix/linux shells What happens in all shells on the same OS is consistent rather than making pwsh on linux “windows like” and annoying linux oriented folks.

1reaction
mklement0commented, Oct 19, 2022

While consistency across platforms is generally desirable, I fear that’s not an option here:

On Unix, if you make / refer to the root of a drive (which on Unix is by definition only ever a PS drive), you won’t be able to change to the actual file-system root whenever the current location is drive-based.

Pragmatically speaking:

  • Interactively, typing, say, Set-Location Temp:/ isn’t too much of a hardship.
  • Programmatically, you can use the following to switch to the root of the current drive, on all platforms (which would obviously be too cumbersome interactively):
    • Set-Location ($PWD.Path -replace '(?<=[\\/]).*')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Vertical ViewPager and Android Pie Inconsistent Behavior ...
My Vertical ViewPager works wonderfully and consistently within any device I have tested and with any OS 5 - 8. I recently upgraded...
Read more >
Inconsistent Data · Stellarium stellarium · Discussion #214
Inconsistent data, which occurs two different ways. repeat event on PC several days apart. Clarification: mark event (e.g. Acronycal Setting of Arcturus on...
Read more >
JFrame (Java SE 11 & JDK 11 )
The JFrame class is slightly incompatible with Frame . Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only...
Read more >
JFrame (Java Platform SE 7 )
getDefaultCloseOperation. Returns the operation that occurs when the user initiates a "close" on this frame.
Read more >
Differences between Windows PowerShell 5.1 and ...
The most notable differences are in the availability and behavior of PowerShell cmdlets between Windows and non-Windows platforms and the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found