From a172c8a8b956dcb4496993d207985b60f01a2cb9 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 16 Nov 2012 11:07:10 -0800 Subject: [PATCH] Fixed $(( ! n )) and incorrect warning on $(($?)) --- ShellCheck/Analytics.hs | 3 ++- ShellCheck/Parser.hs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 9962b4e..9649a90 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -264,7 +264,8 @@ checkDivBeforeMult _ = return () prop_checkArithmeticDeref = verify checkArithmeticDeref "echo $((3+$foo))" prop_checkArithmeticDeref2 = verify checkArithmeticDeref "cow=14; (( s+= $cow ))" prop_checkArithmeticDeref3 = verifyNot checkArithmeticDeref "cow=1/40; (( s+= ${cow%%/*} ))" -checkArithmeticDeref (TA_Expansion _ (T_DollarBraced id str)) | not $ any (`elem` "/.:#%") $ str = +prop_checkArithmeticDeref4 = verifyNot checkArithmeticDeref "(( ! $? ))" +checkArithmeticDeref (TA_Expansion _ (T_DollarBraced id str)) | not $ any (`elem` "/.:#%?*@") $ str = warn id $ "Don't use $ on variables in (( )) unless you want to dereference twice" checkArithmeticDeref _ = return () diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index b91442b..64a158f 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -279,6 +279,7 @@ prop_a6 = isOk readArithmeticContents " 1 | 2 ||3|4" prop_a7 = isOk readArithmeticContents "3*2**10" prop_a8 = isOk readArithmeticContents "3" prop_a9 = isOk readArithmeticContents "a^!-b" +prop_aA = isOk readArithmeticContents "! $?" readArithmeticContents = readSequence where @@ -359,6 +360,7 @@ readArithmeticContents = readNegated = do id <- getNextId op <- oneOf "!~" + spacing x <- readAnySigned return $ TA_Unary id [op] x