koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.45k stars 1.78k forks source link

SC2154 false positive in single/double quoted vars/aliases and inconsistencies #2894

Open pstueck opened 10 months ago

pstueck commented 10 months ago

For bugs

For new checks and feature suggestions

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


#!/bin/bash
alias newalias='_ugs=5 _ug=0 ; echo $_ugs $_ug'

Here's what shellcheck currently says:

SC2154 (warning): _ug is referenced but not assigned.
SC2154 (warning): _ugs is referenced but not assigned.

Here's what I wanted or expected to see:

no warning


On the other hand …


#!/bin/bash
_ugs=9
alias newalias='_ugs=5 ; echo $_ugs $((_ug=_ug+1))'

… is accepted, although I think, _ug should have caused an SC2154

skull-squadron commented 7 months ago

Similar false positives with lower-cased variables in a trap statement despite being referenced. It doesn't happen with upper-cased variable names.

In files/base/installer/texlive line 9:
trap 'e=$?; trap - EXIT; rm -rf "$TEXLIVE_TMP_DIR"; exit $e' EXIT
     ^-- SC2154 (warning): e is referenced but not assigned.