Skip to content

syntax: $var#... is incorrectly parsed as a comment #1003

@emilazy

Description

@emilazy

Example using shfmt:

emily@yuyuko ~> cat test.bash
foo=abc
bar=def
echo foo#bar
echo foo#$bar
echo $foo#bar
echo $foo#$bar
emily@yuyuko ~> bash test.bash
foo#bar
foo#def
abc#bar
abc#def
emily@yuyuko ~> shfmt test.bash
foo=abc
bar=def
echo foo#bar
echo foo#$bar
echo $foo #bar
echo $foo #$bar
emily@yuyuko ~> shfmt test.bash | bash
foo#bar
foo#def
abc
abc

None of these contain comments, but the latter two examples get turned into comments (and this actually came up in practice; see bouk/babelfish#23). I'm not sure if it's just variable substitutions or if there are other circumstances where this incorrect parse happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions