Skip to content

The number of columns is misplaced when the shfmt parses the backquote command with escape symbols. #1028

Closed

Description

@tegixia
  • The shell statement is as follows:
#!/bin/bash
demo=3
last=`echo \\$demo`

After parsing,The number of columns of the keyword ‘\$demo’ is misplaced.It's supposed to be 12 to 19, but it's actually 12 to 18.

  • shfmt parse tree:
[
    {
        "Pos": {
            "Offset": 27,
            "Line": 3,
            "Col": 7
        },
        "End": {
            "Offset": 31,
            "Line": 3,
            "Col": 11
        },
        "Parts": [
            {
                "Type": "Lit",
                "Pos": {
                    "Offset": 27,
                    "Line": 3,
                    "Col": 7
                },
                "End": {
                    "Offset": 31,
                    "Line": 3,
                    "Col": 11
                },
                "ValuePos": {
                    "Offset": 27,
                    "Line": 3,
                    "Col": 7
                },
                "ValueEnd": {
                    "Offset": 31,
                    "Line": 3,
                    "Col": 11
                },
                "Value": "echo"
            }
        ]
    },
    {
        "Pos": {
            "Offset": 33,
            "Line": 3,
            "Col": 12
        },
        "End": {
            "Offset": 39,
            "Line": 3,
            "Col": 18
        },
        "Parts": [
            {
                "Type": "Lit",
                "Pos": {
                    "Offset": 33,
                    "Line": 3,
                    "Col": 12
                },
                "End": {
                    "Offset": 39,
                    "Line": 3,
                    "Col": 18
                },
                "ValuePos": {
                    "Offset": 33,
                    "Line": 3,
                    "Col": 12
                },
                "ValueEnd": {
                    "Offset": 39,
                    "Line": 3,
                    "Col": 18
                },
                "Value": "\\$demo"
            }
        ]
    }
]

Activity

  1. mvdan commented on Dec 26, 2023

    @mvdan
    Owner

    Thanks. This one was quite tricky to figure out, but I think I have now.

  2. added a commit that references this issue on Feb 13, 2024
    28117db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      ⌂ 换网址