Skip to content

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

@antifuchs

Description

@antifuchs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions