何时使用推送位置与设置位置?

jac*_*cus 4 powershell directory-structure

乍一看,在更改当前目录时,Set-LocationPush-Location PowerShell cmdlet看起来很相似.

每个用例是什么?什么时候选择使用一个而不是另一个?

arc*_*444 13

它们都将更改工作目录,但使用时Push-Location会将当前工作目录添加到堆栈顶部,然后再切换到新的工作目录.然后,您可以使用Pop-Location以前的工作目录遍历堆栈.

Set-Location只会改变工作目录cd.

Set-Location = cd
Push-Location = pushd
Pop-Location = popd
Run Code Online (Sandbox Code Playgroud)

  • 一个问题是“Push-Location”不会更改控制台主机中的“[Environment]::CurrentDirectory”,但会更改 ISE 主机中的“[Environment]::CurrentDirectory”。/sf/answers/3952367471/ (3认同)