Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Apr 2006 19:40:31 -0500
From:      Kevin Kinsey <kdk@daleco.biz>
To:        "N. Ersen SISECI" <siseci@gmail.com>
Cc:        Martin McCormick <martin@dc.cis.okstate.edu>, freebsd-questions@freebsd.org
Subject:   Re: Bourn Shell -n Flag Questions
Message-ID:  <4452B5FF.7040304@daleco.biz>
In-Reply-To: <848f55ff0604281642i1262ffc9w499dbd217590f590@mail.gmail.com>
References:  <200604281634.k3SGYNhn093282@dc.cis.okstate.edu> <848f55ff0604281642i1262ffc9w499dbd217590f590@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> On 4/28/06, Martin McCormick <martin@dc.cis.okstate.edu> wrote:
> 
>>         I read about the noexecute flag or -n flag which is supposed
>> to check the syntax of a Bourn Shell script to see what it would do if
>> run, but not actually do anything.  This sounds like a wonderful
>> thing, especially when one is going to run a dangerous script and you
>> only get one chance to get it right.
>>
>>         I tried sh -n scriptname and it always silently succeeds even
>> if I type sh -x -n somescript.  I even deliberately created a script
>> with a syntax error in it and tried sh -x -n again.  It still did
>> nothing but exit.  Does this just not work or am I misunderstanding
>> the purpose of the flag?
>>
>>         Thanks for your help.
>>
N. Ersen SISECI wrote:
 > Hello,
 >
 > Bourne shell is bash. So you should try
 > bash -n scriptname

Um, "Bourne shell" is /bin/sh.  "Bourne Again SHell" is bash, which is 
not installed in FreeBSD by default.

As for "sh -n", consider:

[343] Fri 28.Apr.2006 19:35:03
[kadmin@archangel][~/scripts]# cat foobaz
#!/bin/sh

PRE="Foo
ECHO=/bin/echo
TARGET=/tmp/foobar

$ECHO $PRE > $TARGET

[344] Fri 28.Apr.2006 19:35:20
[kadmin@archangel][~/scripts]# sh -n foobaz
foobaz: 3: Syntax error: Unterminated quoted string

So, it would appear that "-n" is merely a "lint" type option or "syntax 
checker".  Whether or not it's smart enough to catch your error I can't 
tell; it caught mine with and without "-x" ....

HTH,

Kevin Kinsey

-- 
The giraffe you thought you offended last week is willing to be nuzzled
today.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4452B5FF.7040304>