help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] automatic syntax check?


From: Gotmy Nick
Subject: Re: [Help-bash] automatic syntax check?
Date: Sat, 5 Jul 2014 13:44:02 +0200

On 5 July 2014 10:51, Patrick Schleizer <address@hidden> wrote:
> Hi!
>
> How (in)sane would it be to add something like
>
>     bash -n "$0" || exit 1
>
> to the beginning of bash scripts to have some basic syntax checking?
>
> Any other advise for automatic syntax check?


It's not so insane. The main issue, maybe if the script sets some
shell option to extend syntax.

In such case you may need to pass such option to the invocation line
for syntax check too.

For example, if the program contains a line like...

    shopt -s extglob

And it uses extended glob syntax, then you may need to call $0 as:

    bash -n -O extglob "$0" || exit 1

Otherwise you may get a syntax error always (even if the remaining
code is correct for bash).

Other issue could be performance if the original script is fork-free,
and gets called hundreds or thousand of times per second. In such case
it could be more sane to check once after edit, and skip the check on
each call.

Of course, we should know better the reasons for this..

Maybe there are remaining issues if you don't trust people editing the
script. For example, nobody should edit the program while it maybe
called by other users or by cron.


Best regards.
IƱigo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]