Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jan 2005 16:22:45 -0500
From:      Timothy Luoma <lists@tntluoma.com>
To:        FreeBSD-Questions Questions <freebsd-questions@freebsd.org>
Subject:   Re: my lame attempt at a shell script...
Message-ID:  <9C4A9C5E-5DCD-11D9-89A5-000D93AD26C8@tntluoma.com>
In-Reply-To: <0CE27994-5DCD-11D9-89A5-000D93AD26C8@tntluoma.com>
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>

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

[Eric: sorry if you see this twice.  Resending online.  hit REPLY 
instead of REPLY ALL by accident]

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

> First off, let me thank you very much for the massive amount of
> information you've given me thus far.

I am a commandline geek from way back, so you're welcome.

My brother actually had a Dilbert from years ago that he gave me where 
Dilbert runs into a guy with a long beard and suspenders and says "Hey, 
you're one of those Unix geeks, aren't you?"

I wish I could get that on a T-Shirt!

Anyway, the sourcing idea is definitely a good one.  I'm not usually 
working with such easy source material (I do a lot of stuff where I'm 
pulling information off a website, etc)

>   Do me a favor and tell me if
> this syntax is correct:
>
> #!/bin/sh
>
> . /etc/rc.conf
>
> if [ "$grog_firewall_enable" = "YES" ]
> then
>          echo "Firewall enabled."
> elif [ "$grog_firewall_enable" = "NO" ]
> then
>          echo "Firewall disabled."
> fi
>
> exit 0

yes, that's right

> This seems to work when I try it at a command line.  There's one other
> question. How would I add the following line (please correct syntax):
>
> elif [ "$grog_firewall_enable" <> "YES" or "NO" ]
> then
> 		echo "Syntax error in /etc/rc.conf file. grog_firewall_enable must be
> YES or NO"
> fi

Ah, ok.  When you are done with the "elif" (short for "else if" BTW) 
you may use an "ELSE" that covers everything else.

Since you've already matched for YES and NO then all you need is to add 
in a catch-all (NOTE: there is no "THEN" when dealing with ELSE.  only 
IF or ELIF takes a THEN

if [ "$grog_firewall_enable" = "YES" ]
then
          echo "Firewall enabled."

elif [ "$grog_firewall_enable" = "NO" ]
then
          echo "Firewall disabled."

else
	echo "Syntax error in /etc/rc.conf file. grog_firewall_enable must be 
YES or NO"
	
	exit 1
fi

the 'exit 1' is optional.  If you include it, the script will end right 
there, which may or may not be ideal.

TjL



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