#!/usr/bin/env bash# shellcheck source=/dev/nullsource ../init
# helpers does not need to be sourced because it is automatically sourced by init.function check_args(){ lb_check_args_num "${@}"2}function main(){ check_args "one""two""three"# lb_fail bar# lb_die foo}main "${@}"
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# Check if logging has been loaded# shellcheck source=/dev/null[["${LIBBASH_LOG_LEVEL:-}"]]||source"${LIBBASH_DIR}/logging"#------------------------------ Global Variables ------------------------------#------------------------------ Private Functions -----------------------------#------------------------------ Public Functions ------------------------------function lb_die(){ lb_fatalln "${@}"exit1}function lb_fail(){ lb_errorln "${@}"return1}function lb_check_args_num(){# Number of arguments passedn=$(("${#@}"-1))# last argumenti="${*: -1}"if(( i != n ));thenif((i==1));thenarg="arg"elsearg="args"fi lb_fail "$(printf"expected %s %s but got %s""${i}""${arg}""${n}")"fi}
#!/usr/bin/env bash# shellcheck source=/dev/nullsource ../init
# helpers does not need to be sourced because it is automatically sourced by init.function check_args(){ lb_check_args_num "${@}"2}function main(){ check_args "one""two""three"# lb_fail bar# lb_die foo}main "${@}"
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# Check if logging has been loaded# shellcheck source=/dev/null[["${LIBBASH_LOG_LEVEL:-}"]]||source"${LIBBASH_DIR}/logging"#------------------------------ Global Variables ------------------------------#------------------------------ Private Functions -----------------------------#------------------------------ Public Functions ------------------------------function lb_die(){ lb_fatalln "${@}"exit1}function lb_fail(){ lb_errorln "${@}"return1}function lb_check_args_num(){# Number of arguments passedn=$(("${#@}"-1))# last argumenti="${*: -1}"if(( i != n ));thenif((i==1));thenarg="arg"elsearg="args"fi lb_fail "$(printf"expected %s %s but got %s""${i}""${arg}""${n}")"fi}
lb_check_args_num${@}num
Return 0 if the number of arguments passed matches num.
#!/usr/bin/env bash# shellcheck source=/dev/nullsource ../init
# helpers does not need to be sourced because it is automatically sourced by init.function check_args(){ lb_check_args_num "${@}"2}function main(){ check_args "one""two""three"# lb_fail bar# lb_die foo}main "${@}"
#!/usr/bin/env bash: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"# Check if logging has been loaded# shellcheck source=/dev/null[["${LIBBASH_LOG_LEVEL:-}"]]||source"${LIBBASH_DIR}/logging"#------------------------------ Global Variables ------------------------------#------------------------------ Private Functions -----------------------------#------------------------------ Public Functions ------------------------------function lb_die(){ lb_fatalln "${@}"exit1}function lb_fail(){ lb_errorln "${@}"return1}function lb_check_args_num(){# Number of arguments passedn=$(("${#@}"-1))# last argumenti="${*: -1}"if(( i != n ));thenif((i==1));thenarg="arg"elsearg="args"fi lb_fail "$(printf"expected %s %s but got %s""${i}""${arg}""${n}")"fi}