From owner-freebsd-questions@FreeBSD.ORG Mon Jan 3 21:22:46 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 E9D3116A4CE for ; Mon, 3 Jan 2005 21:22:46 +0000 (GMT) Received: from spatula.dreamhost.com (spatula.dreamhost.com [66.33.205.9]) by mx1.FreeBSD.org (Postfix) with ESMTP id C3C7843D46 for ; Mon, 3 Jan 2005 21:22:46 +0000 (GMT) (envelope-from lists@tntluoma.com) Received: from [192.168.2.102] (unknown [68.254.13.39]) by spatula.dreamhost.com (Postfix) with ESMTP id 8605D17D070 for ; Mon, 3 Jan 2005 13:22:44 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v619) 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> <0CE27994-5DCD-11D9-89A5-000D93AD26C8@tntluoma.com> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <9C4A9C5E-5DCD-11D9-89A5-000D93AD26C8@tntluoma.com> Content-Transfer-Encoding: 7bit From: Timothy Luoma Date: Mon, 3 Jan 2005 16:22:45 -0500 To: FreeBSD-Questions Questions X-Mailer: Apple Mail (2.619) Subject: Re: my lame attempt at a shell script... 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: Mon, 03 Jan 2005 21:22:47 -0000 [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