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

Single-quoted solitary item in for loop spuriously triggers SC2041 but not SC2043 #2891

Open
3 of 4 tasks
antifuchs opened this issue Dec 24, 2023 · 2 comments
Open
3 of 4 tasks

Comments

@antifuchs
Copy link

For bugs

  • Rule Id (if any, e.g. SC1000): SC2041
  • My shellcheck version (shellcheck --version or 'online'): online
  • 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:

#!/usr/bin/env bash

for dev in '/dev/disk/by-uuid/28DD-A89E'; do
  echo "$dev"
done

Here's what shellcheck currently says:

Line 3	SC2041: This is a literal string. To run as a command, use $(..) instead of '..' . 

Here's what I wanted or expected to see:

I would not expect this to warn about SC2041, but SC2043. The following snippet where a second single-quoted element is iterated over does not warn about SC2041 (and, correctly, not about SC2043):

#!/usr/bin/env bash

for dev in '/dev/disk/by-uuid/28DD-A89E' 'foo'; do
  echo "$dev"
done

and neither does the following with double quotes (it does warn about SC2043, as expected):

#!/usr/bin/env bash

for dev in "double-quoted"; do
  echo "$dev"
done
@ormaaj
Copy link

ormaaj commented Dec 30, 2023

That word doesn't require quotes anyway so... maybe it's just guessing that it's a command-in-a-string for some reason. Erroneous if so.

This is just silly and hopefully not the actual rationale. There are several noisy and not super useful single-quoting warnings similar to this - where it tries to guess that the content of a single-quoted word was supposed to be something else.

@iFreilicht
Copy link

This is indeed quite annoying, especially when auto-generating scripts, see nix-community/disko#868

In my case, it's also purely about strings that all start with /dev, so I'd be fine if there was just a short list of exceptions that prevented this from triggering. Something like ls or /bin/bash could indeed be a command.

iFreilicht added a commit to nix-community/disko that referenced this issue Nov 11, 2024
Regression introduced in 94bc0f5,
because I developed against unstable, which has
NixOS/nixpkgs#333744 merged, while 24.05
doesn't.

Partly shellchecks mistake, see
koalaman/shellcheck#2891 but whatever, we
can't do much more about it than ignore the warning.

Fixes #868
iFreilicht added a commit to nix-community/disko that referenced this issue Nov 13, 2024
Regression introduced in 94bc0f5,
because I developed against unstable, which has
NixOS/nixpkgs#333744 merged, while 24.05
doesn't.

Partly shellchecks mistake, see
koalaman/shellcheck#2891 but whatever, we
can't do much more about it than ignore the warning.

Fixes #868
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

3 participants