From f1ed4b1d81dcaa04bfdf49e36f3b5e3cc5dfa338 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:29:19 -0500 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 | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index 62f4e72..33f9552 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,5 +1,11 @@ +#!/hint/bash +# This may be included with or without `set -euE` + # License: Unspecified +[[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 +_INCLUDE_COMMON_SH=true + # Avoid any encoding problems export LANG=C -- cgit v1.2.3-70-g09d2