zsh-users
 help / color / mirror / code / Atom feed
From: Guillaume Brunerie <guillaume.brunerie@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: Zsh option for checking if a file is a shell script
Date: Mon, 16 Aug 2010 22:52:15 +0200	[thread overview]
Message-ID: <AANLkTi=1voRSG2ay+oUbL3bOt4GE6434zw+T5p3QXir_@mail.gmail.com> (raw)
In-Reply-To: <100812091209.ZM20191@torch.brasslantern.com>

[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]

2010/8/12 Bart Schaefer <schaefer@brasslantern.com>

> On Aug 12, 12:23pm, Guillaume Brunerie wrote:
> }
> } Is there some option (for example --check-syntax) such that
> } $ zsh --check-syntax /path/to/a/shell/script
> } doesn't do anything except that the return code would be 0
> } if /path/to/a/shell/script is indeed a shell script, and non zero
> otherwise?
>
> $ zsh -n /path/to/some/file
>
> or equivalently but more obviously
>
> $ zsh -o no_exec /path/to/some/file

will parse but not execute the file, and exit with failure if there is
> a parse error.


Thank you :-)


> However, just because a file doesn't cause a parse error
> is not a guarantee that it is a shell script, and parsing a very big
> file is potentially expensive.
>

I want that because I have aliased cat to use 'source-highlight' when given
only one argument (in order to have syntax highlighting in the shell) and
this doesn't work for shell scripts without extension nor shebang (like most
system scripts in /etc).
But it seems indeed that many files are syntactically correct but aren't at
all shell scripts (like /etc/inittab).
If someone knows a better solution, please let me know.

      reply	other threads:[~2010-08-16 20:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-12 10:23 Guillaume Brunerie
2010-08-12 16:12 ` Bart Schaefer
2010-08-16 20:52   ` Guillaume Brunerie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=1voRSG2ay+oUbL3bOt4GE6434zw+T5p3QXir_@mail.gmail.com' \
    --to=guillaume.brunerie@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).