Comments (12)
I'd have to write some C# or something to check.
PSCmdlet.GetUnresolvedProviderPathFromPSPath does this translation, in my test case from "~/.ssh/known_hosts" to "C:\Users\rhubarb\.ssh\known_hosts".
Typically you use GetResolvedProviderPathFromPSPath for -Path and GetUnresolvedProviderPathFromPSPath for -LiteralPath.
So not the command line expansion. not the .NET runtime, it is the PowerShell file system provider.
This translation does other important things like give you the current location per thread, as current directory is a process wide thing.
from powershell.
I agree that the docs should be amended to clarify that the literal aspect of the -LiteralPath
parameter only relates to not treating its arguments as a wildcard pattern, not also to not interpreting an argument-initial ~
(either standalone or if followed by \
or //
) as the home location of the provider underlying the current location (which is interpreted as such irrespective of whether you use -LiteralPath
or -Path
).
(I don't think that changing the current behavior to also treat ~
literally would be considered acceptable, as it is may break existing scripts.)
Note that, unlike in POSIX-compatible shells:
-
Neither interpretation (wildcard patterns,
~
) is a shell expansion, i.e. the interpretation is not performed by the PowerShell engine itself in a command-agnostic fashion; instead, the interpretation is provided by the targeted provider. -
As such, whether a
-LiteralPath
or-Path
argument is quoted or not is irrelevant.
from powershell.
@mklement0 that's interesting that it's not powershell doing it
I think it is PowerShell doing it because there is nobody else doing it, the operating system does not do it. What I think @mklement0 is saying is it is not the command line variable expansion doing it, it is the PowerShell file system provider almost treating ~ as a logical drive.
from powershell.
The docs have been updated.
from powershell.
@mklement0 that's interesting that it's not powershell doing it.. but the same systems using the other 'native' CLI do not have this issue (id est it is the shell expanding ~
)
If the [.net] provider cannot be amended, and the cmdlets wont be changed to escape ~
before handing over to it (to bring it in line with other shells..), it absolutely must be in all documentation (as it functions counter to non-pwsh expectations)
from powershell.
I took it to mean it's .NET doing it, as pwsh would be using it to provide filesystem access, and the other CLI not utilising .NET is why 'nobody else is doing it'. But I could be wrong, I'd have to write some C# or something to check.
If you're right then this definitely falls closer to 'we should change this, not just document it' :/
from powershell.
I suggest making a doc issue to clarify the use of -LiteralPath
,https://github.com/MicrosoftDocs/PowerShell-Docs. (cc @sdwheeler). I will leave it up to working group to decide how to approach this, feels like a pretty niche case but definitely sympathize with the confusing messaging with "literal path"
The official PowerShell documentation sources. Contribute to MicrosoftDocs/PowerShell-Docs development by creating an account on GitHub.
from powershell.
I'm not sure that this is unique to -LiteralPath
. The workaround for the OP is to qualify the path.
/home/sdwheeler> $pwd
Path
----
/home/sdwheeler
/home/sdwheeler> New-Item -Type Directory -name ~
Directory: /home/sdwheeler
UnixMode User Group LastWriteTime Size Name
-------- ---- ----- ------------- ---- ----
drwxr-xr-x sdwheeler sdwheeler 05/06/2024 13:37 4096 ~
/home/sdwheeler> cd ~
/home/sdwheeler> cd ./~
Path
----
/home/sdwheeler/~
from powershell.
Yes, the interpretation of a stand-alone ~
as a path or a ~/
-prefixed path as ~
referring to the provider's home location is unrelated to the -LiteralPath
/ -Path
distinction,
but the point is that it's reasonable to assume that if you use -LiteralPath
that ~
too will be treated literally, so adding a note to the docs would be helpful.
from powershell.
Resolving as the current code behavior would be a breaking change and I do think some folks would be surprised if ~
didn't go home even for -literalpath
.
from powershell.
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.
from powershell.
π£ Hey @Hashbrown777, how did we do? We would love to hear your feedback with the link below! π£οΈ
π https://aka.ms/PSRepoFeedback
from powershell.
Related Issues (20)
- Add support for passing arguments to `Invoke-Expression` HOT 20
- ConvertTo-Json for empty array produces null HOT 9
- Expose default PowerShell User-Agent in Microsoft.PowerShell.Commands.PSUserAgent
- LICENSE.txt HOT 2
- HideTableHeaders is not persisted to Get-FormatData if defined as FormatData rather than in format file. HOT 1
- Using Invoke-WebRequest POST to upload a file is broken HOT 19
- ScriptProperty getters (-Value) can not throw errors HOT 8
- call operator & fails when used with background operator & HOT 6
- "RegisterMicrosoftUpdate.ps1" fails and freezes installer when AppLocker / WDAC rules exist (despite the script being whitelisted & running full language mode) HOT 2
- Cannot build packages from devcontainer
- Invoke-WebRequest fails with βRequest headers must contain only ASCII characters.β for simple requests HOT 2
- [JEA] Register-PSSessionConfiguration does not "cascade" the -NoServiceRestart parameter to Set-PSSessionConfiguration when automatically calling it.
- Feature: Expose `Set-Location` history stack HOT 11
- Surrogate pairs cause misalignment in Format-Wide HOT 19
- Update behavior for getting wix 3.14 in CI.psm1 HOT 1
- is it defined/documented which newlines are used by Write-Host and Out-File HOT 8
- `Remove-Item` throws "Attempted to divide by zero" on PS 7.5.0-preview.3 HOT 6
- `using namespace` overrides previous `using namespace` uses as interactive HOT 8
- [Windows] No error when using a non-executable file in script line HOT 4
- `Remove-Item` reports incorrect number of removed items in the progress bar HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powershell.