-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
Minifying heredoc values in command substitutions produces invalid shell #923
Comments
So this behavior is actually not just with command substitutions, but also exists for heredocs in subshells and in process substitutions too. |
Digging through the code I've at least figured a workaround:
Adding an extra statement after the ending heredoc word allows the formatter to correctly flush the heredoc, I'm guessing because of the new line. Now running
|
diamondburned
pushed a commit
to diamondburned/mvdan-sh
that referenced
this issue
May 9, 2023
Given the shell a=$( cat <<EOF hello EOF ) We would format it into a=$(cat \ <<EOF) hello EOF First, this makes bash unhappy, as it wants to find the closing EOF before we close the command substitution. Teach rightParen to use a newline if there are any pending heredocs, even if we're minifying. Second, the escaped newline before the redirect is unnecessary. Now, we format the shell into a=$(cat <<EOF hello EOF ) Thanks to Andrey Kaipov for the report and test cases. Fixes mvdan#923.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example, running the following file through
shfmt -mn
:Produces the following shell:
Which can't be ran:
For some context, I'm using this kind of pattern to assign literal strings to a variable. I can use something like
read -r -d '' a <<'EOF'
in bash, but afaik assigningcat <<'EOF'
is the way to do something like that with posix sh.The text was updated successfully, but these errors were encountered: