bug-bash
[Top][All Lists]
Advanced

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

Re: Determine if a file is a valid Bash script


From: Stefano Lattarini
Subject: Re: Determine if a file is a valid Bash script
Date: Mon, 19 Mar 2012 21:15:49 +0100

On 03/19/2012 08:54 PM, Lane Schwartz wrote:
> Hi,
> 
> If I have a file that contains a bash script, is there any
> straightforward way of determining whether that script can be parsed
> successfully as a Bash script, without actually running the file?
>
Yes: the "-n" option.  Simple examples:

  $ echo 'if :; then echo not seen; fi' | bash -n; echo status: $?
  status: 0
  $ echo 'if :; then echo not seen' | bash -n; echo status: $?
  bash: line 2: syntax error: unexpected end of file
  status: 2

The bash manual should provide more details.

HTH,
  Stefano



reply via email to

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