Bug#848663: vim: sh syntax highlighting of command substitution $() is wrong

Bas Zoetekouw bas at debian.org
Mon Dec 19 13:34:54 UTC 2016


Hi,

On 19/12/16 14:02, James McCoy wrote:
> On Mon, Dec 19, 2016 at 11:55:50AM +0100, Bas Zoetekouw wrote:
>> Vim's currenr behaviour for syntax highlighting of shell scripts (with
>> #!/bin/sh and /bin/sh pointing to dash) is to mark command
>> substititions using the $(foo) construction as an error.
> 
> Not that I can see.

I've just tried this with a clean strecht system (no ~/.vim* present):
screenshot is attached.  The $(foo) is clearly marked as an error there
(inverse colors in this color scheme), in the same way as real bashisms
like $'' and ${foo%bar}.


>> This is incorrect, as POSIX sh alllows this construction.
>>
>> Because vim's syntaxt hightlighting script correctly identifies
>> /bin/sh-->/bin/dash as a POSIX shell, and sets b:is_posix,
> 
> Which it then translates to b:is_kornshell:
> 
>     if !exists("b:is_kornshell") && !exists("b:is_bash")
>       if exists("g:is_posix") && !exists("g:is_kornshell")
>        let g:is_kornshell= g:is_posix
>       endif
>       if exists("g:is_kornshell")
>         let b:is_kornshell= 1
>         if exists("b:is_sh")
>           unlet b:is_sh
>         endif
> 
> What b:is_ variable is set in that buffer?  Also, see ":help
> ft-sh-syntax", although /bin/sh should be handled as POSIX if it's a
> symlink to dash.

In my case, vim seems to automatically set:
>  filetype=sh
> syntax_on=#1
> b:current_syntax=sh
> b:is_posix=#1
> b:is_sh=#1

but no b_is_kornshell.

Not that in the piece you quoted, only g:is_posix is checked, whereas
sh.vim sets b:is_posix.

BTW, the syntax highlighting is correct if I change the hashbang to
/bin/ksh, /bin/bash or /bin/zsh, but not if I use /bin/sh (like in the
screenshot), /bin/dash, or /bin/ash

Gr,
Bas.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot_2016-12-19_14:34:29_1082x344.png
Type: image/png
Size: 13075 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-vim-maintainers/attachments/20161219/433becc3/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-vim-maintainers/attachments/20161219/433becc3/attachment-0001.sig>


More information about the pkg-vim-maintainers mailing list