mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.15k stars 338 forks source link

shfmt incorrectly reports "unclosed here-document" for tab-indented closing delimiter with <<- #1088

Open jooftian opened 1 month ago

jooftian commented 1 month ago

shfmt is incorrectly reporting an "unclosed here-document" error for a bash script that uses the <<- syntax with a tab-indented closing delimiter. This syntax should be valid according to bash heredoc documentation.

Script content (test.sh):

#!/bin/bash

main() {
    bash <<-EXEC
        uname -a
    EXEC
}

main

Note: The closing EXEC and the content are indented with tabs, not spaces.

Error message:

PS C:\...> shfmt -ln bash -l -w "C:\...\test.sh"
C:\...\test.sh:4:7: unclosed here-document 'EXEC'

Environment:

Additional notes:

Expected behavior: shfmt should recognize the tab-indented closing delimiter and content as valid when using the <<- syntax and not report an "unclosed here-document" error.

Steps to reproduce:

  1. Create a file named test.sh with the content provided above.
  2. Run shfmt -ln bash -l -w "path\to\test.sh"
  3. Observe the "unclosed here-document" error.

Additional readings:

Please let me know if you need any additional information or if there's a workaround for this issue. Thank you for your attention to this matter.

jooftian commented 1 month ago

Even when trying with the following code, the error persist

#!/bin/bash

bash <<-EXEC
    uname -a
EXEC