powershell - 执行脚本和点源一样吗?
问题描述
我最近在 powershell 中看到了一些令人惊讶的行为。
考虑脚本 c:\scripts\tst1.ps:
Set-location c:\
现在从powershell:
C:\scripts PS> .\tst1.ps1
C:\ PS>
为什么调用shell根据“set-location”变成了“C:\”?“set-location”不应该根据其他shell(如bash)的正常脚本规则从子shell运行吗?
我认为您必须“点源”脚本才能获得这种行为???那是: ”。.\tst1.ps1”?这里发生了什么。
是我的主机上的powershell配置错误还是这些天powershell的实际行为?
有没有办法重新配置 powershell 以获得我期望的旧行为,它类似于脚本在子 shell 中运行并退出并且当前目录不受影响的 bash shell?
解决方案
您可以使用新的 powershell 实例运行脚本:
C:\scripts PS> powershell .\tst1.ps1
推荐阅读
- javascript - 为什么'for'循环只返回数组中的最后一项?
- php - 未捕获的错误:在 php 中调用 null 上的成员函数 connection()
- reactjs - React 应用程序在本地运行良好,但在 Heroku 上部署后失败
- node.js - Telegram bot - 每天向用户发送消息
- python - 以货币显示的最大金额
- python - 访问 Heroku 部署的 Flask 应用程序时出错
- python - Python for 循环如何处理列表?
- python - 在 Django 上 Docker 安装 Jupyter 失败
- c++ - 如何在多个函数声明中重用相同的默认参数?
- python - 如何将列表变成字典?