Repository navigation
Conversation
…mand SC2016 is not emitted for single-quoted strings passed to commands like sh, bash, sudo or docker, as those are commonly used to pass a script to a shell. This only works when such a command is the one being run, missing many other cases where a shell is run via a wrapper, such as runc exec ctr sh -c 'echo $HOME' nsenter -t 1 -m bash -eu -o pipefail -c 'echo $HOME' kubectl exec pod -- sh -euc 'echo $HOME' Do not emit SC2016 for a single-quoted argument which immediately follows a shell (sh, bash, dash, etc.) invocation with options ending with one containing -c. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Contributor
Author
e-kwsm
reviewed
Oct 8, 2026
| isShellInvocation _ = False | ||
| endsWithDashC opts = | ||
| case opts of | ||
| [flag] -> "-" `isPrefixOf` flag && not ("--" `isPrefixOf` flag) && 'c' `elem` flag |
Collaborator
There was a problem hiding this comment.
Suggested change
| [flag] -> "-" `isPrefixOf` flag && not ("--" `isPrefixOf` flag) && 'c' `elem` flag | |
| [flag] -> flag `matches` mkRegex "^-[a-zA-Z]*c[a-zA-Z]*$" |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SC2016 is not emitted for single-quoted strings passed to commands like
sh,bash,sudoordocker, as those are commonly used to pass ascript to a shell. This only works when such a command is the one being
run, missing many other cases where a shell is run via a wrapper, e.g.
Do not emit SC2016 for a single-quoted argument which immediately
follows a shell (
sh,bash,dash,ash,ksh,ksh88,ksh93,mksh,oksh,zsh)invocation with options, the last of which contains
c(like-cor-euc). Other arguments (e.g.sh -x '...',sh script -c '...', ora second single-quoted argument after the script) are still reported.
Tested on runc's integration tests: no new warnings, and 6 out of 17
# shellcheck disable=SC2016annotations become unnecessary.Fixes #1894
Fixes #3222