diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index af846a7..4af743c 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -83,6 +83,7 @@ basicChecks = [ ,checkGlobbedRegex ,checkTrapQuotes ,checkTestRedirects + ,checkIndirectExpansion ] treeChecks = [ checkUnquotedExpansions @@ -870,6 +871,19 @@ checkTestRedirects (T_Redirecting id redirs@(redir:_) cmd) | cmd `isCommand` "te warn (getId redir) $ "This is interpretted as a shell file redirection, not a comparison." checkTestRedirects _ = return () +prop_checkIndirectExpansion1 = verify checkIndirectExpansion "${foo$n}" +prop_checkIndirectExpansion2 = verifyNot checkIndirectExpansion "${foo//$n/lol}" +checkIndirectExpansion (T_DollarBraced id (T_NormalWord _ ((T_Literal _ s):attempt:_))) = + case attempt of T_DollarExpansion _ _ -> doit + T_DollarBraced _ _ -> doit + T_DollarArithmetic _ _ -> doit + _ -> return () + where + doit = if all isVariableChar s + then err id "To expand via indirection, use name=\"foo$n\"; echo \"${!name}\"" + else return () +checkIndirectExpansion _ = return () + --- Subshell detection prop_subshellAssignmentCheck = verifyFull subshellAssignmentCheck "cat foo | while read bar; do a=$bar; done; echo \"$a\""