Windows PowerShell 相当于 Unix/Linux `pwd`?

war*_*ren 43 windows linux unix powershell

cmd.exe问题的后续行动中,PowerShell 等价于echo %cd%, 或 Linux/Unix 是pwd什么?

par*_*d0x 49

PowerShell 具有许多与 Linux 相同的命令。pwd是等价的命令。

当您输入pwdPowershell 时,它是Get-Location.

  • “那很容易”..男孩,我是不是觉得很害羞:) (2认同)

Ryn*_*ant 30

除了Get-Location及其别名,您还可以使用自动变量$pwd

$pwd变量很好,因为您可以直接访问 PathInfo 成员。例如

$pwd.Path.PadLeft(80)
$pwd.Drive
Run Code Online (Sandbox Code Playgroud)

如果您想知道有哪些成员,您可以通过管道将 command\alias 传递给Get-Member

PS C:\Users\your-name-here\Desktop> pwd|Get-Member


   TypeName: System.Management.Automation.PathInfo

Name         MemberType Definition
----         ---------- ----------
Equals       Method     bool Equals(System.Object obj)
GetHashCode  Method     int GetHashCode()
GetType      Method     type GetType()
ToString     Method     string ToString()
Drive        Property   System.Management.Automation.PSDriveInfo Drive {get;}
Path         Property   System.String Path {get;}
Provider     Property   System.Management.Automation.ProviderInfo Provider {get;}
ProviderPath Property   System.String ProviderPath {get;}
Run Code Online (Sandbox Code Playgroud)


小智 5

它是pwd。您可以通过将其放在引号中来“串化”它。更何况,你可以建立像这样的路径:"$pwd\bin"