我试图在powershell中模拟bash的源命令.目的是对我进行任何更改microsoft.powershell_profile.psl并将其提供给现有的powershell实例.
以下命令在命令行中有效
$profile_content = [string]::join([environment]::newline,(get-content $profile))
invoke-expression $profile_content
Run Code Online (Sandbox Code Playgroud)
一切都很好; 我把microsoft.powershell_profile.psl它放入,它不起作用.
function source{
$profile_content = [string]::join([environment]::newline,(get-content $args[0]))
invoke-expression $profile_content
}
Run Code Online (Sandbox Code Playgroud)
我忽略了什么吗?
您想要的内容已经内置到PowerShell中:
. C:\path\to\some.ps1
Run Code Online (Sandbox Code Playgroud)
.点源运算符
在当前作用域中运行脚本,以便脚本创建的任何函数,别名和变量都添加到当前作用域.Run Code Online (Sandbox Code Playgroud). c:\scripts.sample.ps1