ctest bash completion syntax error without extglob option
I am encountering this problem with completions installed via Homebrew, but the problem is not specific to brew.
$ bash
bash: /opt/homebrew/etc/bash_completion.d/ctest: line 43: syntax error in conditional expression: unexpected token `('
bash: /opt/homebrew/etc/bash_completion.d/ctest: line 43: syntax error near `@(E'
bash: /opt/homebrew/etc/bash_completion.d/ctest: line 43: ` if [[ $cur == @(Experimental|Nightly|Continuous)* ]]; then'
The @()
syntax requires extglob pattern matching. If shopt extglob
is off
then this error is encountered. Adding shopt -s extglob
to the top of the file avoids the failure, but is not a desirable solution because this file is source
d which will result in the option being changed in the calling shell.
One possible solution is to avoid extglob syntax here. This would be the simplest.
Another possible solution is to use shopt -p extglob
to get a command to restore the current option setting, then shopt -s extglob
to enable the option for the necessary duration, then run the command from -p
to restore the original setting. This would need to be done at the top of the file so that the script is correctly handled during bash loading. Setting the option may also be required within the function, including avoiding affecting the calling shell.