From d163abf993d1fa85d8172e3a4b698ba90f2a113e Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Mon, 24 Sep 2012 15:03:53 +0200 Subject: [PATCH] bash_completion: Enable extglob while parsing file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In older versions of GNU Bash extended patterns, such as “@(…)”, are only available with the “extglob” shell option. As pointed out in [1] and [2], “extglob” must be enabled while parsing the code. Therefore the flag must be enabled at the beginning of the script and be reset to its original value at the end as to not interfere with other code on shell initialization. [1] http://unix.stackexchange.com/questions/45957 [2] http://mywiki.wooledge.org/glob Reported by Sascha Lucas. Signed-off-by: Michael Hanselmann Reviewed-by: Bernardo Dal Seno Reviewed-by: Iustin Pop (cherry picked from commit 893ad76d18e1a8286247e06c8451bbd4831cff8f) --- autotools/build-bash-completion | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion index 365dad9..0cae301 100755 --- a/autotools/build-bash-completion +++ b/autotools/build-bash-completion @@ -622,6 +622,11 @@ def main(): buf = StringIO() sw = utils.ShellWriter(buf) + # Remember original state of extglob and enable it (required for pattern + # matching; must be enabled while parsing script) + sw.Write("gnt_shopt_extglob=$(shopt -p extglob || :)") + sw.Write("shopt -s extglob") + WritePreamble(sw) # gnt-* scripts @@ -638,6 +643,10 @@ def main(): WriteCompletion(sw, "%s/burnin" % constants.TOOLSDIR, "_ganeti_burnin", opts=burnin.OPTIONS, args=burnin.ARGUMENTS) + # Reset extglob to original value + sw.Write("[[ -n \"$gnt_shopt_extglob\" ]] && $gnt_shopt_extglob") + sw.Write("unset gnt_shopt_extglob") + print buf.getvalue() -- 1.7.10.4