Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jan 2005 16:47:59 -0500
From:      Timothy Luoma <lists@tntluoma.com>
To:        Eric F Crist <ecrist@secure-computing.net>
Cc:        FreeBSD-Questions Questions <freebsd-questions@freebsd.org>
Subject:   Re: my lame attempt at a shell script...
Message-ID:  <22B51A59-5DD1-11D9-89A5-000D93AD26C8@tntluoma.com>
In-Reply-To: <4BFD88E8-5DCE-11D9-B56F-000D9333E43C@secure-computing.net>
References:  <06DDB71C-5DB4-11D9-B56F-000D9333E43C@secure-computing.net> <15416223037.20050103193803@hexren.net> <6074EB8D-5DC6-11D9-89A5-000D93AD26C8@tntluoma.com> <F0BE3E23-5DC8-11D9-B56F-000D9333E43C@secure-computing.net> <0CE27994-5DCD-11D9-89A5-000D93AD26C8@tntluoma.com> <4BFD88E8-5DCE-11D9-B56F-000D9333E43C@secure-computing.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On Jan 3, 2005, at 4:27 PM, Eric F Crist wrote:

> Good to know.  If I want to validate, like my first example, against
> some variables, how would I do that best.  Say, for example, I have 4
> possible entries for grog_firewall_enable but I want to single out
> three of them:
>
> if [ "$grog_firewall_enable" <> "YES" OR "NO" OR "OPEN" ]
>
> is this the correct syntax?  Can't seem to figure this one out.

Instead of <> you want to use != when working in (ba)sh.

I no of no way to test A != (B or C or D) on one line like that in bash.

I think the closest you can come is using 'case':

case $grog_firewall_enable in
         YES|NO|OPEN)
                 :
		;;

		*)
			echo Illegal value for grog_firewall_enable
		;;
esac

the ":" in that case is just a placeholder.  You could replace it with 
some commands, even your previous IF/ELIF statements if you wanted to.

TjL

ps - in case it wasn't obvious, and it wasn't to me when I first 
started, "fi" is "if" spelled backwards and "esac" is "case" spelled 
backwards.  Makes it easier to remember how to spell them correctly ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?22B51A59-5DD1-11D9-89A5-000D93AD26C8>