Skip to content

Instantly share code, notes, and snippets.

@heph
Created January 19, 2018 21:18
Show Gist options
  • Save heph/b1668fd56817541895efd48e768d2189 to your computer and use it in GitHub Desktop.
Save heph/b1668fd56817541895efd48e768d2189 to your computer and use it in GitHub Desktop.
Bash - load and execute functions matching a pattern from include files Raw
for file in $(find ./tasks -type f -name '*.sh' | sort -n); do
current_functions="$(declare -F)"
echo "Sourcing task file: ${file}"
# shellcheck source=/dev/null
source "$file"
new_functions="$(diff <(echo "$current_functions") <($(declare -F))) | awk '$NF ~ /.*::main/ {print $NF}')" || true
for main in "$new_functions"; do
log debug "Executing function ${main} from ${file}:"
$main
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment