From 07b5aa2971e4214e972a843fb35b134968e87405 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 17 Oct 2018 20:22:49 -0700 Subject: [PATCH] Add SC2239: shebang is not absolute path. --- CHANGELOG.md | 1 + src/ShellCheck/Analytics.hs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a65713..9078d56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Command line option --wiki-link-count/-W for showing wiki links - SC2236/SC2237: Suggest -n/-z instead of ! -z/-n - SC2238: Warn when redirecting to a known command name, e.g. ls > rm +- SC2239: Warn if the shebang is not an absolute path, e.g. #!bin/sh ### Changed - Most warnings now have useful end positions - SC1117 about unknown double-quoted escape sequences has been retired diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs index 2904812..23ea1e0 100644 --- a/src/ShellCheck/Analytics.hs +++ b/src/ShellCheck/Analytics.hs @@ -432,17 +432,22 @@ prop_checkShebang4 = verifyNotTree checkShebang "#shellcheck shell=sh\nfoo" prop_checkShebang5 = verifyTree checkShebang "#!/usr/bin/env ash" prop_checkShebang6 = verifyNotTree checkShebang "#!/usr/bin/env ash\n# shellcheck shell=dash\n" prop_checkShebang7 = verifyNotTree checkShebang "#!/usr/bin/env ash\n# shellcheck shell=sh\n" +prop_checkShebang8 = verifyTree checkShebang "#!bin/sh\ntrue" +prop_checkShebang9 = verifyNotTree checkShebang "# shellcheck shell=sh\ntrue" +prop_checkShebang10= verifyNotTree checkShebang "#!foo\n# shellcheck shell=sh ignore=SC2239\ntrue" checkShebang params (T_Annotation _ list t) = if any isOverride list then [] else checkShebang params t where isOverride (ShellOverride _) = True isOverride _ = False -checkShebang params (T_Script id sb _) = execWriter $ +checkShebang params (T_Script id sb _) = execWriter $ do unless (shellTypeSpecified params) $ do when (sb == "") $ err id 2148 "Tips depend on target shell and yours is unknown. Add a shebang." when (executableFromShebang sb == "ash") $ warn id 2187 "Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence." + unless (null sb || "/" `isPrefixOf` sb) $ + err id 2239 "Ensure the shebang uses an absolute path to the interpreter." prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"