27 ms·
i only recently noticed that powershell accepts ~ as a shortcut for your user folder. anyone know how long that had been a thing?
by mackrevinack 3y ago
i only recently noticed that powershell accepts ~ as a shortcut for your user folder. anyone know how long that had been a thing?
- sedatk 3y agoSince 1.0, but it’s PowerShell specific.
- chungy 3y agoEven in the Unix world, it's shell-specific, but most shells tend to expand ~ out to $HOME (which in turn gets expanded to the actual path). They also have complicated rules about when ~ characters are expanded or not.
- HeckFeck 3y agoIn cmd you still have the very intuitive %USERPROFILE%. It can be shortened by a custom environment variable if you own the box.
- jasomill 3y agoPowerShell's ~ can be counterintuitive, as it's relative to the current location's path and defined by a property of the current location's PSProvider: PS C:\> Get-PSDrive C,S,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home} Name $_.Provider.Name $_.Provider.Home ---- ---------------- ---------------- C FileSystem C:\Users\jtm S FileSystem C:\Users\jtm HKLM Registry PS C:\Users\jtm> Get-PSDrive C,S,HKCU,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home} Name $_.Provider.Name $_.Provider.Home ---- ---------------- ---------------- C FileSystem C:\Users\jtm S FileSystem C:\Users\jtm HKCU Registry HKLM Registry PS C:\Users\jtm> cd HKLM: PS HKLM:\> cd ~ Set-Location: Home location for this provider is not set. To set the home location, call "(get-psprovider 'Registry').Home = 'path'". PS HKLM:\> (Get-Location).Provider.Home = 'C:\Program Files\Microsoft Office' PS HKLM:\> cd ~ PS C:\Program Files\Microsoft Office> (Get-Location).Provider.Home = 'HKLM:\SYSTEM\CurrentControlSet' PS C:\Program Files\Microsoft Office> cd S: PS S:\> cd ~ PS HKLM:\SYSTEM\CurrentControlSet> (Get-Location).Provider.Home = '..' PS HKLM:\SYSTEM\CurrentControlSet> cd ~ PS HKLM:\SYSTEM> cd ~ PS HKLM:\> Get-PSDrive C,S,HKCU,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home} Name $_.Provider.Name $_.Provider.Home ---- ---------------- ---------------- C FileSystem HKLM:\SYSTEM\CurrentControlSet S FileSystem HKLM:\SYSTEM\CurrentControlSet HKCU Registry .. HKLM Registry .. PS HKLM:\>