Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jooftian opened this issue Aug 14, 2024 · 2 comments

Comments

@jooftian
Copy link

jooftian commented Aug 14, 2024

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.

@jooftian
Copy link
Author

jooftian commented Aug 14, 2024

Even when trying with the following code, the error persist

#!/bin/bash

bash <<-EXEC
	uname -a
EXEC

@mvdan
Copy link
Owner

mvdan commented Sep 29, 2024

Thanks for reporting. You say you're on Windows so this appears to be a bug with CRLF line endings, which I can reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants