From dd115a6d35f6f3efb9b17922073b93c2349867d4 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 25 Jan 2013 20:32:25 -0800 Subject: [PATCH] Warn on trap "echo $num" USR1 --- ShellCheck/Analytics.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index f98e4c9..d83378d 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -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