csh if..then delhema.

Giorgos Keramidas keramida at ceid.upatras.gr
Sat Sep 8 19:08:26 PDT 2007


On 2007-09-08 20:00, Grant Peel <gpeel at 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



More information about the freebsd-questions mailing list