Tuesday, May 21, 2019

(Obscure) problem with bash syntax highlighting

bash allows (yes, it is a "bashism") syntax like:

$ echo ${var:9:5}

To mean extract a substring of the variable, starting at position 9 and of length 5.

But is also allows the offset (and then length, too, but ignore that for now) to be
negative.  But, alas, as noted in "man bash", if the offset is negative, you have to
put a space after the :, in order to avoid ambiguity with the usual ${var:-xxx}
construct.  So, you have to write:

$ echo ${var: -9:5}

Alas, vim flags this as an error.  If I take out the space before the -, the
highlighting is OK.  But with the space, it is flagged as error.

Can this be fixed?

Note: I tried contacting the listed author/maintainer (Charles Campbell) via email first (before posting this), but the mail bounced.  It looks like the sh.vim file hasn't been updated since 2014.

Note also: This was tested under VIM 7.4 (which is what I use).  If it has been fixed in a later version, please let me know.

No comments: