1753787 Members
7756 Online
108799 Solutions
New Discussion юеВ

Troubles with cshell

 
SOLVED
Go to solution
Alex Lavrov.
Honored Contributor

Troubles with cshell

Hello all,

well, for the first time in my life I'm forced to work with cshell and have some problems.

This is my code:

if ("$field_1" =~ ^[a-z]) then
echo "$field_1 IS OK"
else
echo "$field_1 NOT OK!!!"
endif

As I understand it, it matches the strings that begin with a small letters. But ...
As output for "2F2" and "field_1" I get:
2F2 IS OK

Any ideas what might be the problem?

Thanx :)
I don't give a damn for a man that can only spell a word one way. (M. Twain)
22 REPLIES 22
TwoProc
Honored Contributor

Re: Troubles with cshell

Can I sell you a bushel of bash instead?
We are the people our parents warned us about --Jimmy Buffett
Alex Lavrov.
Honored Contributor

Re: Troubles with cshell

Oh, believe me, I wan't and can do it with bash ....

But it must be done with cshell and the worst part is it must run on Sun OS 5.9 ...


:-)
I don't give a damn for a man that can only spell a word one way. (M. Twain)
John Kittel
Trusted Contributor

Re: Troubles with cshell

I don't know csh either. I'm sure if you wait, you'll get an answer from someone who does.

But in the mean time I played with it a little. I wonder if the "!" characters in the echo statement are goofing it up? Try removing them. Just a hunch.
Alex Lavrov.
Honored Contributor

Re: Troubles with cshell

I doubt.

The script doesn't even get there. For some reason "if" returns true.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Robert-Jan Goossens_1
Honored Contributor

Re: Troubles with cshell

I'll check some slowaris c-hell scipts first thing tomorrow morning. Let you know if I can find a clue :-)

Good to see you back in the ITRC Alex! How is the study?
TwoProc
Honored Contributor

Re: Troubles with cshell

#!/usr/bin/csh -c /usr/local/bin/bash
We are the people our parents warned us about --Jimmy Buffett
John Kittel
Trusted Contributor

Re: Troubles with cshell

Uh, sorry. Hope you don't mind another suggestion...

Your example works for me when I change expression in if statement, like this:

if ("$field_1" =~ [a-z]* ) then

Alex Lavrov.
Honored Contributor

Re: Troubles with cshell

Robert:

Well, studies are pretty hard ... As you can see they are torchering me with csh on Sun OS ... And after that I have to write silly game in assembler for PDP11 (think it's grandpa of VAX). Beside that it's OK, but can't say I'm having fun, tho :)


John:

I got "0: Event not found."

I don't give a damn for a man that can only spell a word one way. (M. Twain)
John Kittel
Trusted Contributor

Re: Troubles with cshell

Yes, that is caused by the !s. Remove them and then ( in conjunction with the modified expression ) it may work.

From the HP-UX 11.11 man page:

In an international environment, character ordering is determined by the setting of LC_COLLATE, rather than by the binary ordering of character values in the machine collating sequence. This brings with it certain attendant dangers, particularly when using range expressions in file name generation patterns. For example, the command,

rm [a-z]*

might be expected to match all file names beginning with a lowercase alphabetic character. However, if dictionary ordering is specified by LC_COLLATE, it would also match file names beginning with an uppercase character (as well as those beginning with accented letters). Conversely, it would fail to match letters collated after z in languages such as Norwegian.

The correct (and safe) way to match specific character classes in an international environment is to use a pattern of the form:

rm [[:lower:]]*