1

我有更改当前工作目录的 PS 脚本:

Set-Location (Join-Path (Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Definition)) -ChildPath src)

不幸的是,它会影响父进程环境。因此,当我从终端调用此脚本时,当前目录将在脚本调用后更改。在 Unix 环境中,脚本只能更改本地当前目录,以及脚本的环境变量,不能更改父 shell。

如何改变这种行为?

4

1 回答 1

1
# Create a drive t: in the local scope whose root is c:\temp\backup
# drive t: disappears when the scope (function in this case) is exited
function test {
  New-PSDrive -name "t" -scope local -root c:\temp\backup -PSProvider filesystem; 
  ls t:
}
ls t: # fails unless t: already exists
test  # succeeds
ls t: # fails
于 2013-06-07T00:59:53.817 回答