Date: Wed, 04 May 2005 01:22:23 +0000 From: Chuck Robey <chuckr@chuckr.org> To: Clifton Royston <cliftonr@tikitechnologies.com> Cc: freebsd-questions@freebsd.org Subject: Re: unary operator expected Message-ID: <427823CF.6030100@chuckr.org> In-Reply-To: <20050503232643.GB13135@tikitechnologies.com> References: <AF33154333460E439B317830E50C10490D6072@tmfsrv01.muttart.org> <20050503232643.GB13135@tikitechnologies.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?427823CF.6030100>