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

syntax: give a helpful error message when <<< is used in POSIX mode #881

Closed
hbarcelos opened this issue Jun 14, 2022 · 3 comments · Fixed by #891
Closed

syntax: give a helpful error message when <<< is used in POSIX mode #881

hbarcelos opened this issue Jun 14, 2022 · 3 comments · Fixed by #891

Comments

@hbarcelos
Copy link

shfmt is having issues with the herestring operator (<<<).

The minimum reproducible example:

#!/bin/bash
# script.sh
grep 'foo' <<<'foo'

If I run:

shfmt script.sh

I get:

> script.sh:3:12: << must be followed by a word
@hbarcelos
Copy link
Author

Looks like <<< is not POSIX, so I needed to change shell_variant to bash, then the issue went away.

@mvdan
Copy link
Owner

mvdan commented Jun 14, 2022

Hrm, we should probably give a better error in that case though, because a POSIX << cannot possibly be followed by a <. We already give a helpful error in other scenarios, like when one tries to use Bash arrays in POSIX mode.

@mvdan mvdan reopened this Jun 14, 2022
@mvdan mvdan changed the title Fails to parse herestring <<< syntax: give a helpful error message when <<< is used in POSIX mode Jun 14, 2022
@mvdan
Copy link
Owner

mvdan commented Jun 14, 2022

$ cat array.sh 
foo=(bar)
$ shfmt -ln=bash array.sh 
foo=(bar)
$ shfmt -ln=posix array.sh 
array.sh: array.sh:1:5: arrays are a bash/mksh feature
$ cat herestring.sh 
foo <<< bar
$ shfmt -ln=bash herestring.sh 
foo <<<bar
$ shfmt -ln=posix herestring.sh 
herestring.sh: herestring.sh:1:5: << must be followed by a word

The last one could say something like herestrings are a bash/mksh feature.

@mvdan mvdan closed this as completed in #891 Jul 4, 2022
mvdan pushed a commit that referenced this issue Jul 4, 2022
Fixes #881.

Signed-off-by: Hristiyan Ivanov <hristiyan.d.ivanov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants