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

[SC3028] In a if [ -n BASH_SOURCE ] block don't warn of BASH_SOURCE being undefined #3111

Open
4 tasks done
SamuelMarks opened this issue Dec 31, 2024 · 0 comments
Open
4 tasks done

Comments

@SamuelMarks
Copy link

SamuelMarks commented Dec 31, 2024

For bugs

For new checks and feature suggestions

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

#!/bin/sh

if [ -n "${BASH_VERSION}" ]; then
  # shellcheck disable=SC3028 disable=SC3054
  this_file="${BASH_SOURCE[0]}"
elif [ -n "${ZSH_VERSION}" ]; then
  # shellcheck disable=SC2296
  this_file="${(%):-%x}"
else
  this_file="${0}"
fi

Here's what shellcheck currently says:

When I remove the comments it says:

In POSIX sh, BASH_SOURCE is undefined.
See SC3028.
In POSIX sh, array references are undefined.
See SC3054.

Here's what I wanted or expected to see:

No error

FYI: Similar errors occur with pipefail:

In POSIX sh, set option pipefail is undefined.
See SC3040.

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