Date: Sun, 9 Sep 2007 05:06:57 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Grant Peel <gpeel@thenetnow.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: csh if..then delhema. Message-ID: <20070909020657.GA4912@kobe.laptop> In-Reply-To: <000801c7f274$6fae71e0$6501a8c0@GRANT> References: <000801c7f274$6fae71e0$6501a8c0@GRANT>
index | next in thread | previous in thread | raw e-mail
On 2007-09-08 20:00, Grant Peel <gpeel@thenetnow.com> 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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070909020657.GA4912>
