How is bash not completing this loop and only processing 1 item unless I don't call script X?

Viewed 37

I have the following loop that WORKS...

# Build all modified projects
echo "$PROJECTS_TO_BUILD" | while read PROJECTS; do
    log "Calling build-projects.sh ${PROJECTS}"
    #$DIR/build-projects.sh ${PROJECTS}
done;
echo "I get here in both looping cases"

There is a list of projects on EACH line (separated by newline character). Notice I have one line in that loop commented out. Then I have this loop that doesn't work...

# Build all modified projects
echo "$PROJECTS_TO_BUILD" | while read PROJECTS; do
    log "Calling build-projects.sh ${PROJECTS}"
    #$DIR/build-projects.sh ${PROJECTS}
done;
echo "I get here even though the loop only executed the first thing"

I trimmed the build-projects.sh script down until I found the issue in that one where I call gradle(which is in another loop). If I don't call gradle, everything works and if I call gradle, the loop doesn't work.

I just noticed the gradle wrapper has this at the top while the other scripts are in bash. Does this matter?

#!/usr/bin/env sh

Another trick I tried was just adding & and that works but it needs to block. I wonder, is there an easy way to fork and block and that would fix it perhaps?

0 Answers
Related