0

I have a script on a remote machine which contains a for loop as below:

#!/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

This script is finding all the repos with a build.sh file inside, pulls the latest changes and build them.

This works fine when I execute the scrript on the machine but when I try to trigger this script remotely the for loop just runs once, and I see that it returns a repo which actually doesn't have build.sh at all:

$ 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

I tried to make a one-liner of the for loop and use ssh and that also didn't work. How can I solve this problem?

AVarf
  • 4,481
  • 9
  • 47
  • 74

1 Answers1

3

You need to enable globbing on the remote machine. Add this to the beginning of your script:

shopt -s globstar

Also see this thread

Tarmo
  • 3,728
  • 1
  • 8
  • 25