1753893 Members
7666 Online
108809 Solutions
New Discussion юеВ

Troubles with cshell

 
SOLVED
Go to solution
Alex Lavrov.
Honored Contributor

Re: Troubles with cshell

Well, I removed !s, still no good ...
LC_COLLATE is not even set. The system is pure english.

set field_1 = "2F2"

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


Output:
2F2 IS OK
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

remove !s AND ALSO fix expression...
Alex Lavrov.
Honored Contributor

Re: Troubles with cshell

Nope, tried all variations.

This line works fine:

if (`echo "$field_1" | grep '^[A-Za-z]' | wc -l`)

but with "=~" it doesn't ... I think I miss something in if.
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

ok, sorry, I promise this will be my last post on this. I tried it the way you first presented it and had the same problem as you indicated. Now, with modifications I indicated, it works for me, with HP-UX csh, as following example shows.

# cat tc1.sh
#!/usr/bin/csh
setenv field_1 $1
echo "1 = $1, field_1 = $field_1"
if ("$field_1" =~ [a-z]* ) then
echo "$field_1 IS OK"
else
echo "$field_1 NOT OK"
endif
exit

# ./tc1.sh 2F2
1 = 2F2, field_1 = 2F2
2F2 NOT OK

# ./tc1.sh hello
1 = hello, field_1 = hello
hello IS OK

# ./tc1.sh Hello
1 = Hello, field_1 = Hello
Hello NOT OK
Steven E. Protter
Exalted Contributor

Re: Troubles with cshell

I didnot go to sleep.

#!/usr/bin/csh
setenv field_1 $1
echo "1 = $1, field_1 = $field_1"
if ("$field_1" =~ [a-z]* ) then
echo "$field_1 IS OK"
else
echo "$field_1 NOT OK"
endif
exit

This script tests out okay on Linux c-shell.

I think the suggestion from the previous post will also work on sun.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Alex Lavrov.
Honored Contributor

Re: Troubles with cshell

Thanx, I'll try to make it work.

The final regex, should match words that star with a-z or A-Z and after that contains only numbers and letters.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Mike Stroyan
Honored Contributor

Re: Troubles with cshell

Apart from the
echo "!!!"
being affect by history substitution and the leading "^" not matching front of string like bash, csh has a problem with locale. If you use a locale like LANG=en_US.iso88591 then the [a-z] range will include aBbCcDd...Zz because the collation order doesn't group the lowercase characters together. I don't know of any locale that would make [a-z] match 2.
The csh manual suggests using [[:lower:]] for a locale independent way to match lower case in file name patterns. That does work for file names. It doesn't work for =~.
Alex Lavrov.
Honored Contributor

Re: Troubles with cshell

Oh I see ... so "^" doesn't work as it should normally work, that solves one mystery ...

And now I just need something after [A-Za-z] at the begining of the word, that will match any letter or number, like:
Alex342
aL3Lssd342

But not:
aL34_234
a324 234
etc.

I just can't make some stuff I found working in cshell ..

Thanx in advance.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Mike Stroyan
Honored Contributor

Re: Troubles with cshell

If you happened to have a typo that spelled "than" instead of "then", csh would presume that "than" was some executable name. The if would determine whether to execute "than". It would unconditionally execute the echo line. It would silently pass by the unexpected endif line.

if ( "$field_1" =~ [a-z]* ) than
echo "$field_1 IS OK"
endif
Peter Nikitka
Honored Contributor

Re: Troubles with cshell

Hi,

perhaps it is better to use a switch/case construct, which uses filename matching patterns:

switch ($field_1)
case [a-z]*:
echo starting lower case
breaksw
case [A-Z]*:
echo starting upper case
breaksw
default:
echo starting not with a letter
endsw


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"