Run all shell scripts in folder

Use this:

for f in *.sh; do
  bash "$f" 
done

If you want to stop the whole execution when a script fails:

for f in *.sh; do
  bash "$f" || break  # execute successfully or break
  # Or more explicitly: if this execution fails, then stop the `for`:
  # if ! bash "$f"; then break; fi
done

It you want to run, e.g., x1.sh, x2.sh, ..., x10.sh:

for i in `seq 1 10`; do
  bash "x$i.sh" 
done

To preserve exit code of failed script (responding to @VespaQQ):

#!/bin/bash
set -e
for f in *.sh; do
  bash "$f"
done

There is a much simpler way, you can use the run-parts command which will execute all scripts in the folder:

run-parts /path/to/folder

Tags:

Linux

Shell

Bash