执行的PowerShell脚本中的“ CD”命令仍然会影响当前会话
来自UNIX World,执行(而不是来源)的脚本将在子壳中运行,因此可变声明和cd
命令不会影响实际的当前会话(我们键入命令的会话)。
参考:
# Executing a script
./myscript.ps1
# Sourcing a script
. ./myscript.ps1
比PowerShell相比,非常惊讶(坦率地说)很烦人(坦率地说),执行脚本仍然会影响我有关cd
命令的当前会话(但没有声明的变量)。
我如何防止这种情况发生?
Coming from the Unix world, scripts when executed (as opposed to sourced) are run in a subshell, and thus variable declarations and cd
commands do not affect the actual current session (the one where we type our commands).
For reference:
# Executing a script
./myscript.ps1
# Sourcing a script
. ./myscript.ps1
Very surprised (and quite frankly annoyed) to see than in Powershell, executing a script will still affect my current session regarding cd
commands (but not declared variables).
How can I prevent this from happening ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论