Say you've got a simple bash script
echo $@
Hosted it in a public repo so you can access the raw file like
https://raw.githubusercontent.com/.../test.sh
Then you can run it in a shell like
bash <(curl -s https://raw.githubusercontent.com/.../test.sh) "hello"
I want to be able to achieve this within a gradle task. I've tried:
task testScript(type: Exec) {
workingDir projectDir
executable "bash <(curl -s https://raw.githubusercontent.com/.../test.sh) 'hello'"
}
and
task testScript(type: Exec) {
workingDir projectDir
executable "bash"
args "<(curl -s https://raw.githubusercontent.com/.../test.sh)" 'hello'
}
and
task testScript(type: Exec) {
workingDir projectDir
commandLine "bash", "<(curl -s https://raw.githubusercontent.com/.../test.sh)", "hello"
}
To no avail. What am I doing wrong?
In your original command, <(curl -s https://raw.githubusercontent.com/.../test.sh)
isn't resolved by the bash
command you call, but by the shell from which you call it, the actual command being executed is something like bash /dev/fd/63 "hello"
.
Gradle is no shell and will just call bash
with the string "<(curl -s https://raw.githubusercontent.com/.../test.sh)"
as argument without further processing.
You need to find a command that doesn't need to be expanded by the shell it's being called from. For instance, handling your current command as plain text and using another shell to resolve it :
bash -c 'bash <(curl -s https://raw.githubusercontent.com/.../test.sh) hello'
In conclusion I believe the following should work :
task testScript(type: Exec) {
workingDir projectDir
executable "bash"
args "-c", "bash <(curl -s https://raw.githubusercontent.com/.../test.sh) hello"
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.