Skip to content

Detect variable assignment in eval #3350

@stanio

Description

@stanio

For new checks and feature suggestions

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

#!/bin/sh

# shellcheck disable=SC2034
foo1="bar"
foo2="baz"
foo3="qux"

for i in 1 2 3; do
  eval value="\$foo${i}"
  echo "$value"
done

Here's what shellcheck currently says:

Using version 0.11.0:

In test.sh line 10:
  echo "$value"
        ^----^ SC2154 (warning): value is referenced but not assigned.

For more information:
  https://www.shellcheck.net/wiki/SC2154 -- value is referenced but not assig...

Here's what I wanted to see:

No warnings. Detect a variable has been assigned in eval value=... and don't warn about it: SC2154 (warning): value is referenced but not assigned.

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