my lame attempt at a shell script...

Timothy Luoma lists at tntluoma.com
Mon Jan 3 13:48:01 PST 2005


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 ;-)



More information about the freebsd-questions mailing list