Skip to content

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

@jooftian

Description

@jooftian

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:

  • shfmt version: v3.8.0
  • Go version: go1.23.0 windows/amd64
  • OS: Windows 11 Home Single Language 23H2 22631.3880
  • PowerShell: 5.1.22621.3880
  • VSCode: 1.92.1 (user setup)

Additional notes:

  • The script works correctly when executed.
  • The error occurs both when using shfmt directly and through the VSCode extension.
  • This issue also affects the VSCode extension shell-format, which uses shfmt as a dependency. This suggests the problem has a wider impact on the ecosystem of shell scripting tools.

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.

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