powershell - 如何在linux中调用powershell函数
问题描述
已PowerShell
在 Linux 上安装并创建了如下所示的自定义函数并将其另存为test.ps1
,现在如何ttr
通过将值传递给$file
和来调用该函数$name
#!/usr/bin/env pwsh
function ttr {
Param(
$file,
$name
)
Write-Host $file
Write-Host $name
}
解决方案
我确信可能有其他方法,但这个对我有用
将以下文件保存在/tmp/testscript.ps1
#!/usr/bin/env pwsh
function New-ttr{
Param(
$file,
$name
)
write-host $file
write-host $name
}
创建了另一个像下面这样的脚本并保存在/tmp/callscript.ps1
#!/usr/bin/env pwsh
import-module /tmp/testscript.ps1
New-ttr -file "Test call in PSCore" -name "Testing"
然后
chmod 777 callscript.ps1
./tmp/callscript.ps1
推荐阅读
- python - 连接到 mongo atlas 会给出 pymongo.errors.ServerSelectionTimeoutError: localhost:27017
- azure - 用于实时流式传输的 Azure MediaServices - 延迟时间很长
- javascript - 从 li 中删除子弹
- swift - SwiftUI 组合搜索文本
- python-3.x - 在 Python 中出现意外的 NoneType 错误
- scala - Scala splat 运算符仅用于参数列表的一部分
- python - 按索引过滤熊猫 - Keyerror
- charts - 谷歌图表在 Y 轴上更改总数
- mysql - 如何将 MongoDB 指南针社区数据库应用于我的应用程序?
- javascript - 如何获取css样式规则或html标签样式中设置的样式宽度值