diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 7e5b2da..5724bd5 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -33,6 +33,7 @@ checks = concat [ ,[subshellAssignmentCheck] ,[checkSpacefulness] ,[checkUnquotedExpansions] + ,[checkShebang] ] runAllAnalytics = checkList checks @@ -223,6 +224,14 @@ bracedString l = concat $ deadSimple l isMagicInQuotes (T_DollarBraced _ l) | '@' `elem` (bracedString l) = True isMagicInQuotes _ = False +prop_checkShebang1 = verifyFull checkShebang "#!/usr/bin/env bash -x\necho cow" +prop_checkShebang2 = verifyNotFull checkShebang "#! /bin/sh -l " +checkShebang (T_Script id sb _) m = + if (length $ words sb) > 2 then + let note = Note ErrorC $ "On most OS, shebangs can only specify a single parameter." + in Map.adjust (\(Metadata pos notes) -> Metadata pos (note:notes)) id m + else m + prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done" prop_checkForInQuoted2 = verifyNot checkForInQuoted "for f in \"$@\"; do echo foo; done" prop_checkForInQuoted3 = verify checkForInQuoted "for f in 'find /'; do true; done" diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 18ffe76..dcd5776 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1338,8 +1338,8 @@ wtf = do readShebang = do try $ string "#!" str <- anyChar `reluctantlyTill` oneOf "\r\n" - optional $ carriageReturn - linefeed + optional carriageReturn + optional linefeed return str readScript = do