Warn on trap "echo $num" USR1

This commit is contained in:
Vidar Holen 2013-01-25 20:32:25 -08:00
parent f6f05234bf
commit dd115a6d35
1 changed files with 15 additions and 0 deletions

View File

@ -77,6 +77,7 @@ basicChecks = [
,checkFindExec
,checkValidCondOps
,checkGlobbedRegex
,checkTrapQuotes
]
treeChecks = [
checkUnquotedExpansions
@ -755,6 +756,20 @@ checkGrepRe = checkCommand "grep" f where
when (isGlob re) $ do
warn (getId re) $ "Quote the grep pattern so the shell won't interpret it."
prop_checkTrapQuotes1 = verify checkTrapQuotes "trap \"echo $num\" INT"
prop_checkTrapQuotes2 = verifyNot checkTrapQuotes "trap 'echo $num' INT"
prop_checkTrapQuotes3 = verify checkTrapQuotes "trap \"echo $((1+num))\" EXIT DEBUG"
checkTrapQuotes = checkCommand "trap" f where
f (x:_) = checkTrap x
f _ = return ()
checkTrap (T_NormalWord _ [T_DoubleQuoted _ rs]) = mapM_ checkExpansions rs
checkTrap _ = return ()
warning id = warn id $ "Use single quotes, otherwise this expands now rather than when signalled."
checkExpansions (T_DollarExpansion id _) = warning id
checkExpansions (T_DollarBraced id _) = warning id
checkExpansions (T_DollarArithmetic id _) = warning id
checkExpansions _ = return ()
--- Subshell detection