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

embedded heredoc terminator not properly checked #1050

Closed
vapier opened this issue Nov 15, 2017 · 2 comments
Closed

embedded heredoc terminator not properly checked #1050

vapier opened this issue Nov 15, 2017 · 2 comments

Comments

@vapier
Copy link
Contributor

vapier commented Nov 15, 2017

shellcheck.net incorrectly rejects:

#!/bin/sh
cat <<EOF
foo
EOF hi
EOF

you can change the hi to ; or (just a space) and shellcheck doesn't like any of them. this is a bit of a contrived case, but it came up in two non-contrived scenarios:

  • creating a heredoc of SQL code which itself used a heredoc-like syntax
#!/bin/sh
mysql-like-tool <<EOF
...some SQL...
DEFINE TABLE table1 <<EOF
  ...table logic...
EOF;
...more SQL...
EOF
  • displaying a usage string where the heredoc delimiter happened to show up in the text at the "wrong" place
#!/bin/sh
usage() {
  cat <<EOF
...some block of text...
EOF is reached.
...more block of text...
EOF
}

Here's what shellcheck currently says:

Line 4:
EOF hi
   ^-- SC1122: Nothing allowed after end token. To continue a command, put it on the line with the <<.
@koalaman
Copy link
Owner

Agreed.

This was originally intentional because it was generally what the user seemed to expect, like this perfectly well-formed but wrong snippet:

cat << eof
foo
eof | nl

cat << eof
more stuff
eof

Misparsing a script means you can't simply ignore the issue though, so it should be fixed to flag the (potential) issue while continuing to parse correctly.

@koalaman
Copy link
Owner

This now parses correctly. The warning is still there, but it can be disabled/ignored.

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