`[[[[abc]` generate "incomplete token" error (regression from #12903)
Problem
In 4.8.1:
$ echo [[[[abc]
[[[[abc]In master (commit abaf54f0f8e2f331e4c3038c1cfb21cfbdcc7a04 from PR #12903):
$ echo [[[[abc]
fish: Unexpected end of string, square brackets do not match
echo [[[[abc]
^Notes:
This however never worked:
$ echo [[[[abc # no closing ] fish: Unexpected end of string, square brackets do not match echo [[[[abc ^So in a way, the error is just applied more consistently.
This is related to #2485 and boils down to: When is
[special? When is it just a regular character?- In
$var1[$var2[...and(...)[..., it is obviously special, and the first is what the PR was fixing. - In
[[..., it is obviously not (although arguably, it could be reserved for character ranges/classes like in globbing regex/...) - In
a[b[..., it's unclear. Usually it has no meaning:- currently
setdoes rely on it being special (set var[1 2] ...), at least for the 1st level of nesting - but
echo -e \\e[4mfoofails because of the missing of], even though this ought to be valid
- currently
And if
[is some times special and some times not, what happens with mixed cases, e.g.$var[1 b[...] 2](which]should close$var[? Technically, it should be the 1st], since the 2nd[would have no special meaning, but a user might expect the second).- In
Solution
I think the regression is the lesser evil, at least for now. The PR fixed a valid use case. And if one needs unbalanced brackets, they can use quotes to get around the error. The quotes are already necessary when there are no ] at all.
Maybe a line in the changelog?
Source: fish-shell/fish-shell