From owner-freebsd-questions@FreeBSD.ORG Sat Apr 29 00:41:00 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4EC4A16A40D for ; Sat, 29 Apr 2006 00:41:00 +0000 (UTC) (envelope-from kdk@daleco.biz) Received: from ezekiel.daleco.biz (southernuniform.com [66.76.92.18]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B84A43D69 for ; Sat, 29 Apr 2006 00:40:53 +0000 (GMT) (envelope-from kdk@daleco.biz) Received: from [192.168.2.2] ([69.27.149.254]) by ezekiel.daleco.biz (8.13.4/8.13.1) with ESMTP id k3T0ealS076702; Fri, 28 Apr 2006 19:40:37 -0500 (CDT) (envelope-from kdk@daleco.biz) Message-ID: <4452B5FF.7040304@daleco.biz> Date: Fri, 28 Apr 2006 19:40:31 -0500 From: Kevin Kinsey User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.12) Gecko/20060426 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "N. Ersen SISECI" References: <200604281634.k3SGYNhn093282@dc.cis.okstate.edu> <848f55ff0604281642i1262ffc9w499dbd217590f590@mail.gmail.com> In-Reply-To: <848f55ff0604281642i1262ffc9w499dbd217590f590@mail.gmail.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: Martin McCormick , freebsd-questions@freebsd.org Subject: Re: Bourn Shell -n Flag Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Apr 2006 00:41:01 -0000 > On 4/28/06, Martin McCormick 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.