#!/bin/bash # Variables SUB_SCRIPTS=" \ a.sh \ b.sh \ " # Functions function cmdExists() { if [ ! -e $1 ]; then return 1; else return 0; fi } function hasPermToExec() { if [ ! -x $1 ]; then return 1; else return 0; fi } function executeScript() { sh $1; return $?; } # first parameter is the error description function reportErrorAndExit() { echo "Error: $1"; exit 1; } # Execution starts here for i in $(echo $SUB_SCRIPTS | xargs); do # Check if command exists cmdExists $i if [ "$?" -ne 0 ]; then reportErrorAndExit "Script $i not found"; fi # Check if the user has permission to execute script hasPermToExec $i if [ "$?" -ne 0 ]; then reportErrorAndExit "No permissions to execute script $i"; fi # Execute Script and check return value executeScript $i if [ "$?" -ne 0 ]; then reportErrorAndExit "Script $i exited with an error"; fi done;