Repository navigation
fix(SC2114): issue SC2114 against glob - #3583
Merged
Merged
Conversation
getLiteralString returns Nothing against glob patterns such as `/*`, thus SC2115 was returned; use getGlobOrLiteralString to issue SC2114 resolve koalaman#2833
e-kwsm
commented
Oct 24, 2026
Comment on lines
1145
to
1147
| prop_checkCatastrophicRm3 = verifyNot checkCatastrophicRm "rm -r /home/${USER:?}/*" | ||
| prop_checkCatastrophicRm4 = verify checkCatastrophicRm "rm -fr /home/$(whoami)/*" | ||
| prop_checkCatastrophicRm5 = verifyNot checkCatastrophicRm "rm -r /home/${USER:-thing}/*" |
Collaborator
Author
There was a problem hiding this comment.
rm -rf /home/${USER:?}/* /home/${USER:-thing}/*
Aren’t these destructive?
Owner
There was a problem hiding this comment.
Very destructive, but also intentional.
The idea was the reduce false positives in user provisioning scripts and such that intentionally delete a user's home directory, but triggering on scripts where latent bugs may mean you delete all home directories.
e-kwsm
commented
Oct 24, 2026
| prop_checkCatastrophicRm1 = verify checkCatastrophicRm "rm -r $1/$2" | ||
| prop_checkCatastrophicRm2 = verify checkCatastrophicRm "rm -r /home/$foo" | ||
| prop_checkCatastrophicRm3 = verifyNot checkCatastrophicRm "rm -r /home/${USER:?}/*" | ||
| prop_checkCatastrophicRm4 = verify checkCatastrophicRm "rm -fr /home/$(whoami)/*" |
Collaborator
Author
There was a problem hiding this comment.
As of 776ed08,
$ shellcheck -s sh -f gcc - <<< 'rm -fr /home/"$(whoami)"/*'
-:1:8: warning: Use "${var:?}" to ensure this never expands to /home/* . [SC2115]The hint is unhelpful, and nonnull string leads to a fatal issue.
SC2114?
Owner
There was a problem hiding this comment.
This is indeed pretty unhelpful. I updated the wiki page https://github.com/koalaman/shellcheck/wiki/SC2115 to suggest putting command expansions in variables first, but ideally this would be a more helpful message
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.
getLiteralString returns Nothing against glob patterns such as
/*, thus SC2115 was returned; use getGlobOrLiteralString to issue SC2114resolve #2833