powershell - 批处理脚本中的多行powershell函数
问题描述
我想运行.bat
-script 在其中调用一些 powershell 函数。功能不是那么小,所以我想拆分它。但我做不到,转义符号无济于事(`,^
)。脚本示例:
set file=%1
set function="$file=$Env:file; ^
$hash = CertUtil -hashfile $file SHA256 | Select -Index 1"
powershell -command %function%
解决方案
您可以将引号留在每行的末尾,如下所示:
set file=%1
set function="$file=$Env:file; "^
"$hash = CertUtil -hashfile $file SHA256 | Select -Index 1; "^
"example break line further...."
powershell -command %function%
作为^
多行字符工作,但它也会转义第一个字符,因此也会转义引号。
推荐阅读
- docker - 使用 Docker Desktop 创建 docker-machine
- java - Spring AOP:代表类型声明其他方法或字段
- javascript - 防止 Ramda.omit 将数组转换为对象
- cuda - 如何将内联 PTX 插入 OpenMP 代码?就像我们可以在 Nvidia PTX Assembly 的 CUDA 代码中做的那样?
- javascript - Rollup Javascript API:rollup.watch 进程永不消亡
- angular - 在Angular中重新加载页面后如何保持在同一页面
- url-rewriting - 如何在lucee中实现urlrewrite
- javascript - 如何将 JavaScript 构造函数对象作为 IFFI 函数参数访问?
- ios - Ant Media Server 的 iOS 框架不被 App Store 接受?
- bash - 使用正则表达式进行密码验证在我的 shell 脚本中不起作用