@@ -20,7 +20,7 @@ function script_trap_err() {
2020 set +o pipefail
2121
2222 # Validate any provided exit code
23- if [[ $# -eq 1 && $1 =~ ^[0-9]+$ ]]; then
23+ if [[ ${1-} =~ ^[0-9]+$ ]]; then
2424 exit_code=" $1 "
2525 fi
2626
@@ -77,7 +77,7 @@ function script_exit() {
7777 exit 0
7878 fi
7979
80- if [[ $# -eq 2 && $2 =~ ^[0-9]+$ ]]; then
80+ if [[ ${2-} =~ ^[0-9]+$ ]]; then
8181 printf ' %b\n' " $1 "
8282 # If we've been provided a non-zero exit code run the error trap
8383 if [[ $2 -ne 0 ]]; then
@@ -87,7 +87,7 @@ function script_exit() {
8787 fi
8888 fi
8989
90- script_exit ' Invalid arguments passed to script_exit()!' 2
90+ script_exit ' Missing required argument to script_exit()!' 2
9191}
9292
9393
@@ -205,8 +205,8 @@ function cron_init() {
205205# escape code or one of the prepopulated colour variables.
206206# $3 (optional): Set to any value to not append a new line to the message
207207function pretty_print() {
208- if [[ $# -eq 0 || $# -gt 3 ]]; then
209- script_exit ' Invalid arguments passed to pretty_print()!' 2
208+ if [[ $# -lt 1 ]]; then
209+ script_exit ' Missing required argument to pretty_print()!' 2
210210 fi
211211
212212 if [[ -z ${no_colour-} ]]; then
@@ -241,8 +241,8 @@ function verbose_print() {
241241# OUTS: $build_path: The constructed path
242242# NOTE: Heavily inspired by: https://unix.stackexchange.com/a/40973
243243function build_path() {
244- if [[ -z ${1-} || $ # -gt 2 ]]; then
245- script_exit ' Invalid arguments passed to build_path()!' 2
244+ if [[ $ # -lt 1 ]]; then
245+ script_exit ' Missing required argument to build_path()!' 2
246246 fi
247247
248248 local new_path path_entry temp_path
@@ -272,8 +272,8 @@ function build_path() {
272272# ARGS: $1 (required): Name of the binary to test for existence
273273# $2 (optional): Set to any value to treat failure as a fatal error
274274function check_binary() {
275- if [[ $# -ne 1 && $# -ne 2 ]]; then
276- script_exit ' Invalid arguments passed to check_binary()!' 2
275+ if [[ $# -lt 1 ]]; then
276+ script_exit ' Missing required argument to check_binary()!' 2
277277 fi
278278
279279 if ! command -v " $1 " > /dev/null 2>&1 ; then
@@ -293,10 +293,6 @@ function check_binary() {
293293# DESC: Validate we have superuser access as root (via sudo if requested)
294294# ARGS: $1 (optional): Set to any value to not attempt root access via sudo
295295function check_superuser() {
296- if [[ $# -gt 1 ]]; then
297- script_exit ' Invalid arguments passed to check_superuser()!' 2
298- fi
299-
300296 local superuser test_euid
301297 if [[ $EUID -eq 0 ]]; then
302298 superuser=true
@@ -329,16 +325,16 @@ function check_superuser() {
329325# ARGS: $1 (optional): Set to zero to not attempt execution via sudo
330326# $@ (required): Passed through for execution as root user
331327function run_as_root() {
328+ if [[ $# -eq 0 ]]; then
329+ script_exit ' Missing required argument to run_as_root()!' 2
330+ fi
331+
332332 local try_sudo
333333 if [[ ${1-} =~ ^0$ ]]; then
334334 try_sudo=true
335335 shift
336336 fi
337337
338- if [[ $# -eq 0 ]]; then
339- script_exit ' Invalid arguments passed to run_as_root()!' 2
340- fi
341-
342338 if [[ $EUID -eq 0 ]]; then
343339 " $@ "
344340 elif [[ -z ${try_sudo-} ]]; then
0 commit comments