From owner-freebsd-questions@FreeBSD.ORG Mon Jan 3 21:55:29 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 8037D16A4CE for ; Mon, 3 Jan 2005 21:55:29 +0000 (GMT) Received: from spatula.dreamhost.com (spatula.dreamhost.com [66.33.205.9]) by mx1.FreeBSD.org (Postfix) with ESMTP id 557DB43D39 for ; Mon, 3 Jan 2005 21:55:29 +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 7FFFF17D098; Mon, 3 Jan 2005 13:55:26 -0800 (PST) In-Reply-To: <41D9BA53.4060105@locolomo.org> References: <06DDB71C-5DB4-11D9-B56F-000D9333E43C@secure-computing.net> <15416223037.20050103193803@hexren.net> <6074EB8D-5DC6-11D9-89A5-000D93AD26C8@tntluoma.com> <41D9BA53.4060105@locolomo.org> Mime-Version: 1.0 (Apple Message framework v619) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <2DF07A46-5DD2-11D9-89A5-000D93AD26C8@tntluoma.com> Content-Transfer-Encoding: 7bit From: Timothy Luoma Date: Mon, 3 Jan 2005 16:55:27 -0500 To: Erik Norgaard X-Mailer: Apple Mail (2.619) cc: Eric F Crist cc: FreeBSD-Questions Questions 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:55:29 -0000 On Jan 3, 2005, at 4:34 PM, Erik Norgaard wrote: > Eric F Crist wrote: > >> 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 > > I don't know if you're on 5.x, nor whether you use ipfw, ipfilter or > pf - I wrote a replacement for ipfilter as I got dizzy trying to > maintain a too long ruleset so I wanted to split it into multiple > files. > > On 5.x things get a lot simpler. In /etc/rc.d there are plenty of > scripts to look at - don't look at rc.firewall. [lots of good info snipped] > Finally, don't use bash, use /bin/sh and nothing else, you don't know > if bash is available when your script run. > > Regarding your script, which I got deleted from this mail (sorry), I > think there is an error: > > > if [ "$grog_firewall_enable" = "YES" ] > > this "=" is assignment and will always evaulate to true. You want > > if [ "$grog_firewall_enable" -eq "YES" ] > > I'm not sure if "==" works, but always be careful you're not using > asignment in if-statements. either "-eq" or "=" will work in /bin/sh scripts. Assignment is done like this foo=bar so you have to be careful about quotes and spacing. (Learning PHP was hard because there you DO have to use == and not = Eric - see 'man test' for the proper ways to do greater-than, less-than, greater-or-equal, etc in sh TjL ps - re: this quote: On Jan 3, 2005, at 4:34 PM, Erik Norgaard wrote: > rc.subr also contains a "checkyesno" function answering your question > above - however, it is normal to check "[Yy][Ee][Ss]" and treat > everything else as a no. After all, what are you gonna do if you only > accept "yes" or "no" but some one typed "yeah right"? You must have a > default action. Yeah, I had a Comp. Sci professor who always typed his name in whenever we wrote a program that asked for user input, so if you were expecting a Y|y|n|N and got "cupper" he wanted to know what you planned to do with that.