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

SC2086 false positive on readonly integer variable #2981

Open woodward2 opened 6 months ago

woodward2 commented 6 months ago

For bugs

For new checks and feature suggestions

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

# shellcheck shell=bash

# Prevent the file being sourced more than once by a script.
if [[ -z $alreadySourced ]]; then
        readonly alreadySourced=YES
else
        echo 'Already sourced!'
        return 99
fi

readonly RET_CODE=1

function f0 {
        echo 'in f0'
        return $RET_CODE
}

Here's what shellcheck currently says:

In SHELLCHECKBUG line 15:
        return $RET_CODE
               ^-------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
        return "$RET_CODE"

For more information:
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...

Here's what I wanted or expected to see:

No warning since the variable is a readonly integer.

Note: