zsh-users
 help / color / mirror / code / Atom feed
* Zsh option for checking if a file is a shell script
@ 2010-08-12 10:23 Guillaume Brunerie
  2010-08-12 16:12 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Guillaume Brunerie @ 2010-08-12 10:23 UTC (permalink / raw)
  To: zsh-users

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

Hi,
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?
(in particular I don’t want to execute the shell script at all)
I want to know if a given file is a shell script or not, and I cannot use
the extension or the shebang because some files (e.g. /etc/zprofile) doesn’t
have any of them.

Thank you.

Guillaume Brunerie

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Zsh option for checking if a file is a shell script
  2010-08-12 10:23 Zsh option for checking if a file is a shell script Guillaume Brunerie
@ 2010-08-12 16:12 ` Bart Schaefer
  2010-08-16 20:52   ` Guillaume Brunerie
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2010-08-12 16:12 UTC (permalink / raw)
  To: zsh-users

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.  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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Zsh option for checking if a file is a shell script
  2010-08-12 16:12 ` Bart Schaefer
@ 2010-08-16 20:52   ` Guillaume Brunerie
  0 siblings, 0 replies; 3+ messages in thread
From: Guillaume Brunerie @ 2010-08-16 20:52 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

[-- 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-16 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 10:23 Zsh option for checking if a file is a shell script Guillaume Brunerie
2010-08-12 16:12 ` Bart Schaefer
2010-08-16 20:52   ` Guillaume Brunerie

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).