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

SC2031 is reported even if the subshell is in a different code path #3068

Open
2 tasks done
ale5000-git opened this issue Oct 6, 2024 · 0 comments
Open
2 tasks done

Comments

@ale5000-git
Copy link

ale5000-git commented Oct 6, 2024

For bugs

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

#!/usr/bin/env sh
# shellcheck enable=all

my_func()
{
  if test "${1-}" = '-' && test "${#}" -eq 1; then
    (
      # shellcheck disable=SC2030 # Intended: Modification of LC_ALL is local (to subshell)
      LC_ALL='C'
      export LC_ALL

      some_code
    )
  else
    _old_lcall="${LC_ALL-}"
    LC_ALL='C'
    export LC_ALL

    some_other_code

    if test -n "${_old_lcall?}"; then LC_ALL="${_old_lcall:?}"; else unset LC_ALL; fi
  fi
}

my_func '-'

Here's what shellcheck currently says:

[Line 15:](javascript:setPosition(15, 17))
    _old_lcall="${LC_ALL-}"
                ^-- [SC2031](https://www.shellcheck.net/wiki/SC2031) (info): LC_ALL was modified in a subshell. That change might be lost.

Here's what I wanted or expected to see:

Nothing.
Since the subshell is in a different code path it cannot affect the code at line 15 so it shouldn't report it.

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