![](/img/trans.png)
[英]How to return a status code from a remotely run shell script to a local shell script
[英]How to run a shell script hosted remotely from a Gradle task
假设你有一个简单的 bash 脚本
echo $@
将其托管在公共存储库中,以便您可以访问原始文件,例如
https://raw.githubusercontent.com/.../test.sh
然后你可以在 shell 中运行它
bash <(curl -s https://raw.githubusercontent.com/.../test.sh) "hello"
我希望能够在 gradle 任务中实现这一点。 我试过了:
task testScript(type: Exec) {
workingDir projectDir
executable "bash <(curl -s https://raw.githubusercontent.com/.../test.sh) 'hello'"
}
和
task testScript(type: Exec) {
workingDir projectDir
executable "bash"
args "<(curl -s https://raw.githubusercontent.com/.../test.sh)" 'hello'
}
和
task testScript(type: Exec) {
workingDir projectDir
commandLine "bash", "<(curl -s https://raw.githubusercontent.com/.../test.sh)", "hello"
}
无济于事。 我究竟做错了什么?
在您的原始命令中, <(curl -s https://raw.githubusercontent.com/.../test.sh)
不是由您调用的bash
命令解析的,而是由您调用它的 shell 解析的,正在执行的实际命令类似于bash /dev/fd/63 "hello"
。
Gradle 不是 shell,只会使用字符串"<(curl -s https://raw.githubusercontent.com/.../test.sh)"
作为参数调用bash
,无需进一步处理。
您需要找到一个不需要被调用它的 shell 扩展的命令。 例如,将当前命令作为纯文本处理并使用另一个 shell 来解析它:
bash -c 'bash <(curl -s https://raw.githubusercontent.com/.../test.sh) hello'
总之,我认为以下应该有效:
task testScript(type: Exec) {
workingDir projectDir
executable "bash"
args "-c", "bash <(curl -s https://raw.githubusercontent.com/.../test.sh) hello"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.