koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts

Home Page:https://www.shellcheck.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SC2086 false positive on readonly integer variable

woodward2 opened this issue · comments

For bugs

  • Rule Id (if any, e.g. SC1000): SC2086
  • My shellcheck version (shellcheck --version or "online"): 0.10.0 and online
  • 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

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:

  • changing the return on line 8 to exit removes the spurious warning, but return should be valid here.
  • adding a call of f0 also removes the warning, but since the file is a library of functions, not calling a function is expected.
  • changing # shellcheck shell=bash to #!/bin/bash has no effect on the spurious warning.