假设你有一个简单的 bash 脚本
echo $@
将其托管在公共(public)存储库中,因此您可以访问原始文件,例如
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 不是外壳,只会调用 bash
使用字符串 "<(curl -s https://raw.githubusercontent.com/.../test.sh)"
作为参数,无需进一步处理。
您需要找到一个不需要被调用它的 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"
}
关于bash - 如何运行从 Gradle 任务远程托管的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60190278/