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

$value in <<< $value doesn't need to be quoted #1009

Open
1 of 4 tasks
sgtpep opened this issue Sep 19, 2017 · 5 comments
Open
1 of 4 tasks

$value in <<< $value doesn't need to be quoted #1009

sgtpep opened this issue Sep 19, 2017 · 5 comments

Comments

@sgtpep
Copy link

sgtpep commented Sep 19, 2017

For bugs

  • Rule Id (if any, e.g. SC1000): SC2034
  • My shellcheck version (shellcheck --version or "online"): 0.4.4
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit
  • It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

#!/bin/bash
var="foo   bar"
cat <<< $var

Here's what shellcheck currently says:

Line 3:
cat <<< $var
^-- SC2086: Double quote to prevent globbing and word splitting.

Here's what I wanted or expected to see:

Nothing.

@koalaman
Copy link
Owner

This is true in Bash 4, but not in Bash 3.

host1$ echo "$BASH_VERSION"; var='foo    bar'; cat <<< $var
4.4.12(1)-release
foo    bar

host2$ echo "$BASH_VERSION"; var='foo    bar'; cat <<< $var
3.2.57(1)-release
foo bar

Though I'm not necessarily saying it shouldn't be fixed.

@vapier
Copy link
Contributor

vapier commented Nov 15, 2017

fwiw, the bash-4.4 man page says:

Here Strings
A variant of here documents, the format is:
[n]<<<word

The word undergoes brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal. Pathname expansion and word splitting are not performed. The result is supplied as a single string, with a newline appended, to the command on its standard input (or file descriptor n if n is specified).

@nepella
Copy link

nepella commented May 1, 2019

I was curious enough to look through Bash's changelog: the old behavior of expanding the here string is described as a bug and was fixed in bash-4.4-beta.

@Tamaranch
Copy link

I think that this should be fixed, because it's quite confusing.
Furthermore, scrolling the web quickly, there is no clear answer to the question of whether or not to quote variables in bash here strings.
I had to use github search engine in issues of this repository to find the answer above (and I thought to use it because I know shellcheck, obviously).

@MichaIng
Copy link

MichaIng commented Apr 4, 2022

Just found the same. Interestingly in our case SC2086 is not triggered, but only SC2248 is, while the variable is dynamically generated, so can definitely contain magic characters. So either the false positive is fixed for SC2086 but not for SC2248, or it is not correctly detected that the here string variable is not assured to not contain magic characters. It the second is verified to be true, I'll create a new issue about this.

EDIT: After some shellcheck update, also in our case SC2086 is now thrown. So both rules suffer from the same false positive.

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

6 participants