mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-16 10:03:08 -07:00
Warn if a shebang's interpreter ends in / (fixes #373)
This commit is contained in:
parent
1835ebd3a0
commit
e0a4241baa
2 changed files with 10 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
## Since previous release
|
||||
### Added
|
||||
- Preliminary support for fix suggestions
|
||||
- SC2246: Warn if a shebang's interpreter ends with /
|
||||
- SC2245: Warn that Ksh ignores all but the first glob result in `[`
|
||||
- SC2243/SC2244: Suggest using explicit -n for `[ $foo ]`
|
||||
|
||||
|
|
|
@ -474,6 +474,8 @@ prop_checkShebang7 = verifyNotTree checkShebang "#!/usr/bin/env ash\n# shellchec
|
|||
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"
|
||||
prop_checkShebang11= verifyTree checkShebang "#!/bin/sh/\ntrue"
|
||||
prop_checkShebang12= verifyTree checkShebang "#!/bin/sh/ -xe\ntrue"
|
||||
checkShebang params (T_Annotation _ list t) =
|
||||
if any isOverride list then [] else checkShebang params t
|
||||
where
|
||||
|
@ -485,8 +487,13 @@ checkShebang params (T_Script id sb _) = execWriter $ do
|
|||
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) $
|
||||
unless (null sb) $ do
|
||||
unless ("/" `isPrefixOf` sb) $
|
||||
err id 2239 "Ensure the shebang uses an absolute path to the interpreter."
|
||||
case words sb of
|
||||
first:_ ->
|
||||
when ("/" `isSuffixOf` first) $
|
||||
err id 2246 "This shebang specifies a directory. Ensure the interpreter is a file."
|
||||
|
||||
|
||||
prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue