shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Local variable escaped from the function

Open A4-Tacks opened this issue 1 year ago • 0 comments

For bugs

  • Rule Id: SC2154
  • My shellcheck version:
    ShellCheck - shell script analysis tool
    version: 0.9.0
    license: GNU General Public License, version 3
    website: https://www.shellcheck.net
    
  • [ ] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
  • [ ] I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit

For new checks and feature suggestions

  • [ ] https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
  • [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related

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

#!/bin/bash
f() {
    local x=
}
echo "$x"

Here's what shellcheck currently says:

Here's what I wanted or expected to see:


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

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

A4-Tacks avatar Aug 25 '24 17:08 A4-Tacks