csh if..then delhema.
Garrett Cooper
youshi10 at u.washington.edu
Sat Sep 8 20:27:33 PDT 2007
Giorgos Keramidas wrote:
> 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
>
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
More information about the freebsd-questions
mailing list