Improve: Better script vs. source context detection in menu-functions.sh
IMPROVEMENTS: - Line 20-27: Replace 'return || exit' pattern with explicit context check - Uses BASH_SOURCE check to determine if running as script or sourced - Clearer intent: exit for scripts, return for sourced libraries Rationale: 'return 2>/dev/null || exit' works but is confusing. Explicit 'if' with BASH_SOURCE check is clearer and more maintainable. RESULTS: - Library behavior more explicit and easier to understand - Better error handling for version mismatches
This commit is contained in:
@@ -20,7 +20,11 @@ set -eo pipefail
|
|||||||
# Bash version check
|
# Bash version check
|
||||||
if [ "${BASH_VERSINFO[0]}" -lt 4 ] || ([ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -lt 1 ]); then
|
if [ "${BASH_VERSINFO[0]}" -lt 4 ] || ([ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -lt 1 ]); then
|
||||||
echo "[ERROR] menu-functions.sh requires Bash 4.1 or later (detected: ${BASH_VERSION})" >&2
|
echo "[ERROR] menu-functions.sh requires Bash 4.1 or later (detected: ${BASH_VERSION})" >&2
|
||||||
return 1 2>/dev/null || exit 1
|
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user