diff --git a/bin/list_all_entities_exported.sh b/bin/list_all_entities_exported.sh index 05bee2a..9b67bf1 100755 --- a/bin/list_all_entities_exported.sh +++ b/bin/list_all_entities_exported.sh @@ -49,7 +49,7 @@ display_help () { LOG_LEVEL The global log level [0..5] All of the above environment variables are REQUIRED - (except LOG_LEVEL, which defaults to LOG_LEVEL=3). + except LOG_LEVEL, which defaults to LOG_LEVEL=3. EXAMPLES @@ -64,51 +64,31 @@ HELP_MSG script_name=${0##*/} # equivalent to basename $0 -# check the bin directory -if [ -z "$BIN_DIR" ]; then - echo "ERROR: $script_name requires env var BIN_DIR" >&2 - exit 2 -fi -if [ ! -d "$BIN_DIR" ]; then - echo "ERROR: $script_name: directory does not exist: $BIN_DIR" >&2 - exit 2 -fi - -# check the source lib directory -if [ -z "$LIB_DIR" ]; then - echo "ERROR: $script_name requires env var LIB_DIR" >&2 - exit 2 -fi -if [ ! -d "$LIB_DIR" ]; then - echo "ERROR: $script_name: directory does not exist: $LIB_DIR" >&2 - exit 2 -fi - -# check the cache directory -if [ -z "$CACHE_DIR" ]; then - echo "ERROR: $script_name requires env var CACHE_DIR" >&2 - exit 2 -fi -if [ ! -d "$CACHE_DIR" ]; then - echo "ERROR: $script_name: directory does not exist: $CACHE_DIR" >&2 - exit 2 -fi - -# check the tmp directory -if [ -z "$TMPDIR" ]; then - echo "ERROR: $script_name requires env var TMPDIR" >&2 - exit 2 -fi -if [ ! -d "$TMPDIR" ]; then - echo "ERROR: $script_name: directory does not exist: $TMPDIR" >&2 - exit 2 -fi +# required directories +env_vars="BIN_DIR +LIB_DIR +CACHE_DIR +TMPDIR" + +# check required directories +for env_var in $env_vars; do + eval "env_var_val=\${$env_var}" + if [ -z "$env_var_val" ]; then + echo "ERROR: $script_name requires env var $env_var" >&2 + exit 2 + fi + if [ ! -d "$env_var_val" ]; then + echo "ERROR: $script_name: directory does not exist: $env_var_val" >&2 + exit 2 + fi +done # check the log file if [ -z "$LOG_FILE" ]; then echo "ERROR: $script_name requires env var LOG_FILE" >&2 exit 2 fi +# devices such as /dev/tty and /dev/null are allowed if [ ! -f "$LOG_FILE" ] && [[ $LOG_FILE != /dev/* ]]; then echo "ERROR: $script_name: file does not exist: $LOG_FILE" >&2 exit 2