From owner-freebsd-questions@FreeBSD.ORG Sun Sep 9 03:27:33 2007 Return-Path: Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1F10A16A41A for ; Sun, 9 Sep 2007 03:27:33 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout4.cac.washington.edu (mxout4.cac.washington.edu [140.142.33.19]) by mx1.freebsd.org (Postfix) with ESMTP id D26B813C45B for ; Sun, 9 Sep 2007 03:27:32 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.32.141] (may be forged)) by mxout4.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.06) with ESMTP id l893QnLb023055 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 8 Sep 2007 20:26:49 -0700 X-Auth-Received: from [192.168.10.45] (c-24-10-12-194.hsd1.ca.comcast.net [24.10.12.194]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l893QmmP006317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 8 Sep 2007 20:26:49 -0700 Message-ID: <46E367F7.6060705@u.washington.edu> Date: Sat, 08 Sep 2007 20:26:47 -0700 From: Garrett Cooper User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Giorgos Keramidas References: <000801c7f274$6fae71e0$6501a8c0@GRANT> <20070909020657.GA4912@kobe.laptop> In-Reply-To: <20070909020657.GA4912@kobe.laptop> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.3.3.310218, Antispam-Engine: 2.5.2.313940, Antispam-Data: 2007.9.8.200737 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' Cc: Grant Peel , freebsd-questions@FreeBSD.ORG Subject: Re: csh if..then delhema. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Sep 2007 03:27:33 -0000 Giorgos Keramidas wrote: > On 2007-09-08 20:00, Grant Peel wrote: > >> Hi all, >> >> I have tried every escape sequence I can think of, and I still get >> Division by 0 error here.. >> >> if ($filesystem == "\/") then >> $fsname = $fsnm1 >> elseif ($filesystem == '/var') then >> $fsname =$fsnm2 >> elseif ($filesystem == '/usr') then >> $fsname = $fsnm3 >> elseif ($filesystem == '/home') then >> $fsname = $fsnm4 >> else >> $fsname = 'GREATERTHAN4 >> >> Any ideas how to excape the forward slashes in the if statemnt? >> > > Use a better scripting language? > > Seriously now, unless you are willing to experiment with csh until you > get its 'weird' escaping rules to work, you should consider using > something with a more predictable way of escaping string literals. > > For example, there is nothing above which cannot be done a lot more > easily with Perl and a hash table: > > %fsmap = ( > '/' => $fsnm1, > '/var' => $fsnm2, > '/usr' => $fsnm3, > '/home' => $fsnm4, > ); > > $fsname = $fsmap{$filesystem} or 'unknown'; > > Using the hash results in much 'cleaner' code too. > > Now, go forth and convert a csh script to Perl, Python, or something > with a cleaner syntax :) > > - Giorgos > Or if you want to stick with Unix scripting... #!/bin/sh case "$filesystem" in '/') fsname=$fsnm1;; '/var') fsname=$fsnm2;; '/usr') fsname=$fsnm3;; '/home') fsname=$fsnm4;; *) echo "Oops.. that fs is unknown"; exit 1 ;; esac There ya go. The single quotes are optional in the case statement, but bourne compatible shells are semi-regex intelligent, so to avoid to any problems, I single-quoted the strings. tcsh can burn in hell for all I care. It's a horrible shell IMNHO (in my not-so humble opinion). Now if I could only convince the rest of the EE community to agree, that'd be nice. Trolls welcome :). -Garrett