我在远程机器上有一个脚本,其中包含如下的for循环:
#!/bin/bash -eux
# execute build.sh in each component
for f in workspace/**/**/build.sh ; do
echo $f
REPO=${f%*build.sh}
echo $REPO
git -C ./$REPO checkout master
git -C ./$REPO pull origin master
$f
done
这个脚本正在查找所有包含build.sh
文件的repo,提取最新的更改并构建它们。
当我在机器上执行scrript时,这很好,但当我试图远程触发这个脚本时,for循环只运行一次,我看到它返回了一个实际上根本没有build.sh
的repo:
$ ssh devops "~/build.sh"
+ for f in workspace/**/**/build.sh
+ echo 'workspace/**/**/build.sh'
+ REPO='workspace/**/**/'
+ echo workspace/core/auth/
workspace/**/**/build.sh
workspace/core/auth/
+ git -C ./workspace/core/auth/ checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.
+ git -C ./workspace/core/auth/ pull origin master
From https://gitlabe.com/workspace/core/auth
* branch master -> FETCH_HEAD
Already up to date.
+ 'workspace/**/**/build.sh'
/home/devops/build.sh: line 10: workspace/**/**/build.sh: No such file or directory
我试图制作一行for循环并使用ssh,但也并没有成功。我该如何解决这个问题?
您需要在远程机器上启用globbing。将此添加到脚本的开头:
shopt -s globstar
另请参阅此线程