From owner-freebsd-questions@FreeBSD.ORG Wed May 4 01:23:43 2005 Return-Path: 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 0117B16A4CE for ; Wed, 4 May 2005 01:23:43 +0000 (GMT) Received: from april.chuckr.org (april.chuckr.org [66.92.151.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1EFC443D8A for ; Wed, 4 May 2005 01:23:42 +0000 (GMT) (envelope-from chuckr@chuckr.org) Received: from [66.92.151.195] (july.chuckr.org [66.92.151.195]) by april.chuckr.org (Postfix) with ESMTP id EF9EA11ED8; Tue, 3 May 2005 21:17:36 -0400 (EDT) Message-ID: <427823CF.6030100@chuckr.org> Date: Wed, 04 May 2005 01:22:23 +0000 From: Chuck Robey User-Agent: Mozilla Thunderbird 1.0 (X11/20050316) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Clifton Royston References: <20050503232643.GB13135@tikitechnologies.com> In-Reply-To: <20050503232643.GB13135@tikitechnologies.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: Chris Burchell cc: freebsd-questions@freebsd.org Subject: Re: unary operator expected X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2005 01:23:43 -0000 Clifton Royston wrote: > On Tue, May 03, 2005 at 05:13:47PM -0600, Chris Burchell wrote: > >>I'm working with a script written for Linux that has the following >>lines: >> >># Check that networking is up. >>[ ${NETWORKING} = "no" ] && exit 0 > > > I don't think it's a Linux/BSD issue. This line won't work in sh if > NETWORKING is unset. Then you get (after parameter expansion) > > [ = "no" ] && exit 0 > > which fails the syntax check. That's a very well known mistake you ran into ... you did it wrong. You assumed that $(NETWORKING) == NO is the same as $(NETWORKING) = "" (empty) and they are not equal. You need to insure that $NETWORKING) eitgher always has a value, or you have to shortcircuit the test with a test for the variable's existence and length. Being honest, if I were doing it, I would use NETWORKING as a macro value, something that could immediately test the network's viability, then operate upon that's results. > > I suspect "NETWORKING" always happened to be set in the Linux > environment you were running it under, or perhaps you were using a > different shell. > > >>Can anyone help with suggestions or an alternate statement that will >>work on FreeBSD 5.3-RELEASE? > > > One time-honored idiom is: > > [ "X${NETWORKING}" = "Xno" ] && exit 0 > > or you can just make sure that NETWORKING always gets set to some > value. > > -- Clifton >