我正在构建一个 gradle Exec
任务,这意味着只调用一个基本的 sed
命令,假设:sed -i 's:some:substitution: ' *
什么是正确的语法或 gradle 函数/变量来使 *
glob 替换为它在某些 bash/zsh shell 中匹配的文件?
也就是说,如何触发shell展开?
到目前为止我尝试的是:
task myTask(type: Exec){
workingDirsome dir
commandLine 'sed', '-i', 's:some:substitution:', "*"
}
但我得到一个错误:sed: can't read *: No such file or directory
,这并不奇怪。
最佳答案
您需要启动包裹在外壳中的命令:
commandLine 'bash', '-c', 'sed -i "s:some:substitution:" *'
关于bash - 在 gradle exec 任务中使用 bash glob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25178363/