Sign in before continuing.
check function args
Currently, functions will assign their arg variables to local variables without checking of the caller actually passed values for these args. Example:
scan_file() {
local filename="$1"
# ... ect. ...
}
It would increase robustness to check these args before assigning them, like:
# positive check, see if value IS there and continue if all is OK
scan_file() {
if [[ -n "${1}" ]]; then
local filename="$1"
fi
# ... ect. ...
}
# negative check, see if value IS NOT there and exit if there's a missing value
scan_file() {
if [[ -z "${1}"; then
echo "ERROR: expected ARG for \$1, got nothing." && exit 1
fi
# ... ect. ...
}
# both of those can be combined into their short form as well, like:
( [[ -n "${1}" ]] && local filename="${1}" ) || exit 1