From c1a056c9a8f42e1a8e1f66b265b7ccbd1a2cb1ee Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 2 Apr 2017 04:10:02 -0400 Subject: lib/common.sh: Make it safe to include multiple times. This is similar to common C #ifdef guards. I was tempted to wrap the entire thing in the if/fi, rather than use 'return' to bail early. However, that means it won't execute anything until after it reaches 'fi'. And if `shopt -s extglob` isn't executed before parsing, then it will syntax-error on the extended globs. One solution would have been to move `shopt -s extglob` up above the include-guard. But the committed solution is all-around simpler. --- lib/common.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index 4536668..c9afc36 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -3,6 +3,9 @@ # License: Unspecified +[[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 +_INCLUDE_COMMON_SH=true + # Avoid any encoding problems export LANG=C -- cgit v1.2.3-24-g4f1b