shellcheck --version or "online"): 0.7.0#!/bin/bash
shopt -s extglob;
for f in /etc/hosts/host\.!(mail)\.conf ; do
echo "$f";
done;
error| syntax error near unexpected token `('
no error at all.
my memory lane is slow, but drop-out is fast:
re-hit this bug, wanted to report the bug, found my previously created issue..
Are you using Ale? I think this is an error emitted by bash -n, not Shellcheck.
@bewuethr wazzat, Ale? -n? never used -n. Care to elaborate on this?
Sorry, didn't give any context. Ale is a Vim plugin that lets you asynchronously run linters. For shell scripts, it defaults to shellcheck and bash -n for linting. -n is described like this in the manual:
Read commands but do not execute them. This may be used to check a script for syntax errors. This option is ignored by interactive shells.
So, for a minimal script with an extended "except" glob
$ cat poc
#!/usr/bin/env bash
shopt -s extglob
echo !(foo)
shellcheck doesn't complain, but bash -n does, with the exact error message you're mentioning above:
$ shellcheck poc
$ bash -n poc
poc: line 4: syntax error near unexpected token `('
poc: line 4: `echo !(foo)'
That's why I'm thinking that this isn't a shellcheck message. The shellcheck codebase doesn't include "unexpected token" anywhere, as far as I can tell.
Whoa. Thanks. But. No. Not using Ale. Straight shellcheck only.
Can escape the glob for shellcheck to make it happy. Won't execute, though. What will execute, won't pass shellcheck.
But how do you run shellcheck? If I paste the snippet from your question, neither shellcheck.net nor my locally installed shellcheck complain. How can I reproduce what you see?
Try to downgrade to a shellcheck version prior to the merge, i.e. 0.7.0 (see my initial report).
I use 0.7.0, which seems to be the most recent release :man_shrugging:
Now, _that_ is interesting. What distribution package are you using then?
UPDATE:
(darn, my previous edit got lost in space)
Tested using
shellcheck test.sh
No error.
Opening test.sh with the conflicting content in post #1 results in the error given above.
So it seems shellcheck is indeed not the culprit here but rather the vim-shellcheck plugin.
Thanks @bewuethr for making me realise that shellcheck is not to be blamed here. Heading off to vim-shellcheck, then.
Most helpful comment
my memory lane is slow, but drop-out is fast:
re-hit this bug, wanted to report the bug, found my previously created issue..