Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SC2086 false positive on readonly integer variable #2981

Open
2 tasks done
woodward2 opened this issue May 9, 2024 · 0 comments
Open
2 tasks done

SC2086 false positive on readonly integer variable #2981

woodward2 opened this issue May 9, 2024 · 0 comments

Comments

@woodward2
Copy link

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant