From 1a0e208cc3962410f40f77e869546cb631187380 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 12 Oct 2014 14:00:17 -0700 Subject: [PATCH] Consider find -exec when warning about vars in single quotes. --- ShellCheck/Analytics.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index d460104..1c2467e 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -956,6 +956,8 @@ prop_checkSingleQuotedVariables5 = verifyNot checkSingleQuotedVariables "trap 'e prop_checkSingleQuotedVariables6 = verifyNot checkSingleQuotedVariables "sed -n '$p'" prop_checkSingleQuotedVariables6a= verify checkSingleQuotedVariables "sed -n '$pattern'" prop_checkSingleQuotedVariables7 = verifyNot checkSingleQuotedVariables "PS1='$PWD \\$ '" +prop_checkSingleQuotedVariables8 = verify checkSingleQuotedVariables "find . -exec echo '$1' {} +" +prop_checkSingleQuotedVariables9 = verifyNot checkSingleQuotedVariables "find . -exec awk '{print $1}' {} \\;" checkSingleQuotedVariables params t@(T_SingleQuoted id s) = when (s `matches` re) $ if "sed" == commandName @@ -967,7 +969,10 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) = "Expressions don't expand in single quotes, use double quotes for that." commandName = fromMaybe "" $ do cmd <- getClosestCommand parents t - getCommandBasename cmd + name <- getCommandBasename cmd + if name == "find" + then return $ getFindCommand cmd + else return name isProbablyOk = any isOkAssignment (take 3 $ getPath parents t) @@ -992,6 +997,16 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) = re = mkRegex "\\$[{(0-9a-zA-Z_]" sedContra = mkRegex "\\$[dpsaic]($|[^a-zA-Z])" + + getFindCommand (T_SimpleCommand _ _ words) = + let list = map getLiteralString words + cmd = dropWhile (\x -> x /= Just "-exec" && x /= Just "-execdir") list + in + case cmd of + (flag:cmd:rest) -> fromMaybe "find" cmd + _ -> "find" + getFindCommand (T_Redirecting _ _ cmd) = getFindCommand cmd + getFindCommand _ = "find" checkSingleQuotedVariables _ _ = return ()