Sunday, May 26, 2019

Obscure shell syntax hifghlighting problem: Solved!

On 2019/05/21 13:17, someone replied thusly to 'J S' via vim_use wrote:
>> 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?

>Not that it fixes the syntax, but I've always used "${var:0-9:5}" so the field
>would clearly stand out as starting with an integer and not the ambiguous
>'dash'.  Is that flagged as an error too? 

Thank you!  Changing the space to a zero does both of these thngs:

1) Clears the VIM syntax highlighting error.

2) Does not change the bash functionality.

That zero works in bash is, of course, not mentioned in "man bash".  How did you figure that out?
Maybe I should take it up with the bash maintainer.

No comments:

Post a Comment