gpt4 book ai didi

shell - 在 Windows Powershell 和命令提示符中推送

转载 作者:行者123 更新时间:2023-12-03 00:23:16 28 4
gpt4 key购买 nike

我的计算机上有一个批处理脚本,名为 cs.bat .当我输入 cs在命令提示符中,pushd将我带到某个目录并将我留在那里。在 PowerShell 中,该命令执行相同的操作,但会将我带回起始目录。
为什么会这样?在 Power Shell 中键入“cs”后,如何才能使其留在目录中?
Windows PowerhShell versus Windows command prompt and batch file edited in Notepad

最佳答案

Powershell 包括 Pushd 和 Popd 的别名。

Get-Alias Pushd : pushd -> Push-Location
Get-Alias Popd : popd -> Pop-Location

然后您可以使用 Get-Help Push-Location -Full -Online获取该 cmdlet 的最新帮助。

然后只需编写一个脚本并测试此行为。
#Sample.ps1 script

#Get current DIR
dir

#push location to some location and DIR there.
Push-Location C:\Scripts\
dir

#at this point, your console will still be in the Push-Location directory
#simply run the Pop-Location cmdlet to switch back.

关于shell - 在 Windows Powershell 和命令提示符中推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39421471/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com