shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2154 false positive when declaring variables with `command`

Open mfederczuk opened this issue 2 years ago • 0 comments

For bugs

  • Rule Id: SC2154
  • My shellcheck version: 0.7.1
  • [x] The rule's wiki page does not already cover this (https://shellcheck.net/wiki/SC2154)
  • [x] I tried on https://www.shellcheck.net and verified that this is still a problem on the latest commit

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

#!/bin/bash

command declare x=y

echo "$x"

Here's what shellcheck currently says:

In script line 5:
echo "$x"
      ^-- SC2154: x is referenced but not assigned.

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

Here's what I wanted or expected to see:

No error, since x is assigned.

The same error also happens when using local, readonly or typeset and when putting a backslash before command.

mfederczuk avatar Mar 20 '22 14:03 mfederczuk