From ecb7bbe0ea31888cef2772c6913f2f5065042767 Mon Sep 17 00:00:00 2001 From: Gandalf- Date: Fri, 11 Jan 2019 10:17:44 -0800 Subject: [PATCH] Issue 1330 unsupported echo flags Issue https://github.com/koalaman/shellcheck/issues/1330 Addresses false positives when quoted arguments to echo begin with what looks like a flag. Now, warn only when the first argument is a recognized echo flag when flags are unsupported. --- src/ShellCheck/Checks/ShellSupport.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ShellCheck/Checks/ShellSupport.hs b/src/ShellCheck/Checks/ShellSupport.hs index 7f30224..b642a20 100644 --- a/src/ShellCheck/Checks/ShellSupport.hs +++ b/src/ShellCheck/Checks/ShellSupport.hs @@ -145,6 +145,7 @@ prop_checkBashisms62 = verify checkBashisms "#!/bin/sh\nexport -f foo" prop_checkBashisms63 = verifyNot checkBashisms "#!/bin/sh\nexport -p" prop_checkBashisms64 = verify checkBashisms "#!/bin/sh\nreadonly -a" prop_checkBashisms65 = verifyNot checkBashisms "#!/bin/sh\nreadonly -p" +prop_checkBashisms66 = verifyNot checkBashisms "#!/bin/sh\necho \"-n foo\"" checkBashisms = ForShell [Sh, Dash] $ \t -> do params <- ask kludge params t @@ -231,7 +232,7 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do warnMsg id "` do warnMsg (getId arg) "echo flags besides -n" else warnMsg (getId arg) "echo flags are" - where argString = concat $ oversimplify arg + where + argString = concat $ oversimplify arg + echoFlags = ["-e", "-E", "-s", "-n"] bashism t@(T_SimpleCommand _ _ (cmd:arg:_)) | t `isCommand` "exec" && "-" `isPrefixOf` concat (oversimplify arg) = warnMsg (getId arg) "exec flags are"