Giorgos Keramidas wrote:
On 2007-09-08 20:00, Grant Peel <[EMAIL PROTECTED]> 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
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"