Home > Software engineering >  Find and Execute Scripts in Subdirectories
Find and Execute Scripts in Subdirectories

Time:07-30

I have a filesystem structured like this:

  • Parent Directory
    • orchestrator
      • init.sh
    • Subdir1
      • install.sh
    • Subdir2
      • install.sh
    • Subdir3
      • install.sh

Within the init.sh, I have:

#!/bin/bash
set -e

######################
# Run all installers #
######################

cd "$(dirname $0)"/..

# find the installers and run them interatively
find ../ -name install.sh -type f -exec chmod a x {} \;
find . -name install.sh | while read installer ; do sh -c "${installer}" ; done

This works for the most part, but it is fragile. If one of the install.sh scripts encounters a problem, the init.sh script stops. I'd like for it to continue on to the next install.sh script if this happens. But I'm not sure how to get that to work.

CodePudding user response:

Replacing sh -c "${installer}" with sh -c "${installer} || true" should work, since true always returns 0.

  • Related