gpt4 book ai didi

windows - 与 bash 的 exec() 等效的 PowerShell 是什么?

转载 作者:可可西里 更新时间:2023-11-01 13:42:30 30 4
gpt4 key购买 nike

这里是 PowerShell 的新手。在不创建子 shell 的情况下从当前进程中运行新脚本的最佳方法是什么?在 Bash 中,您可以通过以下方式执行此操作:

source script # Executes the commands in script within the current shell

exec script # Same as source, except it completely replaces the current process with script

PowerShell 中是否有相应的等效项?

最佳答案

你也可以使用.\Script.ps1

或者开始键入名称并使用 TAB 来完成脚本名称。

点源脚本允许函数在命令行上可用。

例如:

Function Get-LocalTime { 

$CurTime = Get-Date

"The Date and time currently is $CurTime"

}

现在我们点源(将上面的脚本命名为 Example.ps1)PS C:\>。 .\Example.ps1

允许我们简单地键入和 Tab 完成 Get-LocalTime

http://i.imgur.com/17xfn6L.png

-编辑注释,您可以定义一个函数并立即在同一个脚本中使用该函数。所以在 Example.ps1 中,在最后一行输入 Get-LocalTime

关于windows - 与 bash 的 exec() 等效的 PowerShell 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34465479/

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