Skip to content

Commit 72af76f

Browse files
committed
Supress SC2093 when execfail is set (fixes #3178)
1 parent 8ff0c5b commit 72af76f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/ShellCheck/Analytics.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,9 @@ prop_checkSpuriousExec8 = verifyNot checkSpuriousExec "exec {origout}>&1- >tmp.l
18961896
prop_checkSpuriousExec9 = verify checkSpuriousExec "for file in rc.d/*; do exec \"$file\"; done"
18971897
prop_checkSpuriousExec10 = verifyNot checkSpuriousExec "exec file; r=$?; printf >&2 'failed\n'; return $r"
18981898
prop_checkSpuriousExec11 = verifyNot checkSpuriousExec "exec file; :"
1899-
checkSpuriousExec _ = doLists
1899+
prop_checkSpuriousExec12 = verifyNot checkSpuriousExec "#!/bin/bash\nshopt -s execfail; exec foo; exec bar; echo 'Error'; exit 1;"
1900+
prop_checkSpuriousExec13 = verify checkSpuriousExec "#!/bin/dash\nshopt -s execfail; exec foo; exec bar; echo 'Error'; exit 1;"
1901+
checkSpuriousExec params t = when (not $ hasExecfail params) $ doLists t
19001902
where
19011903
doLists (T_Script _ _ cmds) = doList cmds False
19021904
doLists (T_BraceGroup _ cmds) = doList cmds False

src/ShellCheck/AnalyzerLib.hs

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ data Parameters = Parameters {
8989
hasSetE :: Bool,
9090
-- Whether this script has 'set -o pipefail' anywhere.
9191
hasPipefail :: Bool,
92+
-- Whether this script has 'shopt -s execfail' anywhere.
93+
hasExecfail :: Bool,
9294
-- A linear (bad) analysis of data flow
9395
variableFlow :: [StackData],
9496
-- A map from Id to Token
@@ -226,6 +228,10 @@ makeParameters spec = params
226228
BusyboxSh -> isOptionSet "pipefail" root
227229
Sh -> True
228230
Ksh -> isOptionSet "pipefail" root,
231+
hasExecfail =
232+
case shellType params of
233+
Bash -> isOptionSet "execfail" root
234+
_ -> False,
229235
shellTypeSpecified = isJust (asShellType spec) || isJust (asFallbackShell spec),
230236
idMap = getTokenMap root,
231237
parentMap = getParentTree root,

0 commit comments

Comments
 (0)