From owner-freebsd-questions@FreeBSD.ORG Sun Sep 9 02:08:26 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 990A516A41A for ; Sun, 9 Sep 2007 02:08:26 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 0055F13C458 for ; Sun, 9 Sep 2007 02:08:25 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (dialup2.ach.sch.gr [81.186.70.2]) (authenticated bits=128) by igloo.linux.gr (8.14.1/8.14.1/Debian-9) with ESMTP id l8927UCI030958 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 9 Sep 2007 05:08:10 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.1/8.14.1) with ESMTP id l8927D1N004986; Sun, 9 Sep 2007 05:07:22 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.1/8.14.1/Submit) id l8926vTx004977; Sun, 9 Sep 2007 05:06:57 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Sun, 9 Sep 2007 05:06:57 +0300 From: Giorgos Keramidas To: Grant Peel Message-ID: <20070909020657.GA4912@kobe.laptop> References: <000801c7f274$6fae71e0$6501a8c0@GRANT> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000801c7f274$6fae71e0$6501a8c0@GRANT> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.873, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.53, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: 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 02:08:26 -0000 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