问题描述
我通常在Az CLI
脚本中使用bash
命令来管理Azure
资源。有时,由于PowerShell core
版本不存在,我需要利用Az CLI
命令。
我想在Az CLI
外壳程序中同时使用PS core
和bash
命令。我的意思是,我想拥有only one
bash脚本并在其中执行所有必需的命令。
您知道在bash脚本中直接直接运行PowerShell core
命令的方法吗?
解决方法
您不能那样做。但是您可以将Powershell用于Linux(pwsh)-https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7
例如从bash开始,您可以调用该程序并传递命令
$ pwsh -c "write-host Hello world"
Hello world
,
通常,如果需要执行许多命令,我会从bash内部调用PowerShell脚本,但是如果您只想执行一个命令,则可以运行pwsh -command COMMAND 例: pwsh -command get-childitem