From 893ad76d18e1a8286247e06c8451bbd4831cff8f Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> 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=UTF-8 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 <hansmi@google.com> Reviewed-by: Bernardo Dal Seno <bdalseno@google.com> --- autotools/build-bash-completion | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion index 359f7a85e..8687254e0 100755 --- a/autotools/build-bash-completion +++ b/autotools/build-bash-completion @@ -639,6 +639,11 @@ def main(): buf = StringIO() sw = utils.ShellWriter(buf, indent=not options.compact) + # 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, not options.compact) # gnt-* scripts @@ -656,6 +661,10 @@ def main(): not options.compact, 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() -- GitLab