Shellcheck: stop parsing after an unconditional exit

Created on 26 Oct 2016  路  2Comments  路  Source: koalaman/shellcheck

several scripts in the wild append data or text after an exit

a few examples

it's useful but shellcheck just dies with messages like this

In ./.git/hooks/pre-rebase.sample line 101:
   merged into it again (either directly or indirectly).
                        ^-- SC1036: '(' is invalid here. Did you forget to escape it?
                        ^-- SC1088: Parsing stopped here. Invalid use of parentheses?

Most helpful comment

(sorry for incoherent thoughts)

Maybe a stop directive? And add warning for code following an unconditional exit/exec (albeit rare, but there are situations where scripts make room for exec failing).

Where scripts that need trailing data can add a # shellcheck stop-parsing or similar, and others would get warnings that they've kept dead code in their scripts.

Maybe just me, but I have forgotten random debug exits in scripts...

All 2 comments

Not just an exit, also an exec. A simple example:

exec cat "$0"
echo $PATH

triggers SC2086, even though line 2 is data.

(sorry for incoherent thoughts)

Maybe a stop directive? And add warning for code following an unconditional exit/exec (albeit rare, but there are situations where scripts make room for exec failing).

Where scripts that need trailing data can add a # shellcheck stop-parsing or similar, and others would get warnings that they've kept dead code in their scripts.

Maybe just me, but I have forgotten random debug exits in scripts...

Was this page helpful?
0 / 5 - 0 ratings