# Description: Template for bash scripts.
# Note: Use hide-show-block function to aid readability. (ex: https://www.emacswiki.org/emacs/HideShow ).
-#== Variable Initialization ==
+#==BEGIN Variable Initialization==
-#== Global constants ==
+#===BEGIN Global constants===
SCRIPT_TTL=10 # Limit script life to this in seconds.
PATH="/usr/local/bin/:$PATH" # Add user binary executable directory to PATH.
PATH="/opt/bktei:$PATH" # Add 'optional' executable directory to PATH.
SCRIPT_VERSION="bktemplate.sh 0.0.0" # Define version of script. Used by function 'showVersion'.
SCRIPT_TIME_SHORT="$(date +%Y%m%dT%H%M%S%z)" # Save current date & time in ISO-8601 format (YYYYmmddTHHMMSS+zzzz).
SCRIPT_DATE_SHORT="$(date +%Y%m%d)" # Save current date in ISO-8601 format.
+#===END Global constants===
-#==BEGIN Define script parameters
+#===BEGIN Define script parameters
declare -Ag appRollCall # Associative array for storing app status (function checkapp())
declare -Ag fileRollCall # Associative array for storing file status (function checkfile())
-#==END Define script parameters
-
-#== Function Definitions ==
-
+#===END Define script parameters
+#==END Variable Initialization==
+#==BEGIN Function Definitions==
yell() { echo "$0: $*" >&2; } # Yell, Die, Try Three-Fingered Claw technique; # Ref/Attrib: https://stackoverflow.com/a/25515370
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }
if [ "$OPTION_VERBOSE" = "true" ]; then
FUNCTION_TIME=$(date --iso-8601=ns); # Save current time in nano seconds.
- echoerr "[$FUNCTION_TIME] ""$@"; # Display argument text.
+ echoerr "[$FUNCTION_TIME] ""$*"; # Display argument text.
fi
# End function
# Perform work
while [ ! $# -eq 0 ]; do # While number of arguments ($#) is not (!) equal to (-eq) zero (0).
#1>&2 echo "DEBUG:Starting processArguments while loop." # Debug stderr message. See [1].
- #1>&2 echo "DEBUG:Provided arguments are:""$@" # Debug stderr message. See [1].
+ #1>&2 echo "DEBUG:Provided arguments are:""$*" # Debug stderr message. See [1].
case "$1" in
-h | --help) showUsage; exit 1;; # Display usage.
--version) showVersion; exit 1;; # Show version
vbm "DEBUG:checkExecutables function called."
declare -a candidateCommandsNames # Initialize array for storing positional arguments provided to this function.
candidateCommandsNames=("$@") # Save positional arguments to variable as string. See [3].
- vbm "DEBUG:candidateCommandsNames:""$@"
+ vbm "DEBUG:candidateCommandsNames:""$*"
vbm "DEBUG:candidateCommandsNames[0]:""${candidateCommandsNames[0]}"
vbm "DEBUG:candidateCommandsNames[1]:""${candidateCommandsNames[1]}"
vbm "DEBUG:candidateCommandsNames[2]:""${candidateCommandsNames[2]}"
# Output: adds/updates key(value) to global assoc array 'appRollCall'
local returnState
#echo "DEBUG:$(date +%S.%N)..Starting checkapp function."
- #echo "DEBUG:args: $@"
+ #echo "DEBUG:args: $*"
#echo "DEBUG:returnState:$returnState"
#===Process Args===
for arg in "$@"; do
#echo "DEBUG:processing arg:$arg"
- if command -v $arg 1>/dev/null 2>&1; then # Check if arg is a valid command
+ if command -v "$arg" 1>/dev/null 2>&1; then # Check if arg is a valid command
appRollCall[$arg]="true";
#echo "DEBUG:appRollCall[$arg]:"${appRollCall[$arg]}
if ! [ "$returnState" = "false" ]; then returnState="true"; fi
return 1;
fi
} # Check that file exists
-
-
-#== Main Program Definition ==
main() {
# Usage: main "$@" # See [1].
# Input: unspecified (note: all Global Constants declared at beginning of script assumed to be available)
# End function
vbm "DEBUG:main function ended."
return 0; # Function finished.
-}
+} # Main function
+#==END Function Definitions==
-#== Perform work and exit ==
+#==BEGIN Perform work and exit==
main "$@" # Run main function.
exit 0;
+#==END Perform work and exit==