- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Troubles with cshell
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 07:44 AM
06-08-2006 07:44 AM
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 :)
Solved! Go to Solution.
- Tags:
- csh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:04 AM
06-08-2006 08:04 AM
Re: Troubles with cshell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:41 AM
06-08-2006 08:41 AM
Re: Troubles with cshell
But it must be done with cshell and the worst part is it must run on Sun OS 5.9 ...
:-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:43 AM
06-08-2006 08:43 AM
Re: Troubles with cshell
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:48 AM
06-08-2006 08:48 AM
Re: Troubles with cshell
The script doesn't even get there. For some reason "if" returns true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:54 AM
06-08-2006 08:54 AM
Re: Troubles with cshell
Good to see you back in the ITRC Alex! How is the study?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:54 AM
06-08-2006 08:54 AM
Re: Troubles with cshell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:55 AM
06-08-2006 08:55 AM
Re: Troubles with cshell
Your example works for me when I change expression in if statement, like this:
if ("$field_1" =~ [a-z]* ) then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 09:02 AM
06-08-2006 09:02 AM
Re: Troubles with cshell
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."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 09:06 AM
06-08-2006 09:06 AM
Re: Troubles with cshell
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:]]*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 09:09 AM
06-08-2006 09:09 AM
Re: Troubles with cshell
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 09:11 AM
06-08-2006 09:11 AM
Re: Troubles with cshell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 09:25 AM
06-08-2006 09:25 AM
Re: Troubles with cshell
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 09:29 AM
06-08-2006 09:29 AM
Re: Troubles with cshell
# 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 09:58 AM
06-08-2006 09:58 AM
Re: Troubles with cshell
#!/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
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 10:06 AM
06-08-2006 10:06 AM
Re: Troubles with cshell
The final regex, should match words that star with a-z or A-Z and after that contains only numbers and letters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 10:16 AM
06-08-2006 10:16 AM
Re: Troubles with cshell
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 =~.
- Tags:
- locale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 10:20 AM
06-08-2006 10:20 AM
Re: Troubles with cshell
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 10:25 AM
06-08-2006 10:25 AM
Re: Troubles with cshell
if ( "$field_1" =~ [a-z]* ) than
echo "$field_1 IS OK"
endif
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:55 PM
06-08-2006 08:55 PM
Re: Troubles with cshell
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
- Tags:
- switch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 08:58 PM
06-08-2006 08:58 PM
Re: Troubles with cshell
Now I'm looking for regexp that beside cheking that word starts with a letter, will check that the other symbols are only letters or numbers.
All the stuff I try, just don't work in csh ... (tcsh).
thanx in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 11:37 PM
06-08-2006 11:37 PM
Solutionto come to your request
Now I'm looking for regexp that beside cheking that word starts with a letter, will check that the other symbols are only letters or numbers.
Starting with my switch/case but exiting/breaking in
default:
you can continue in stripping all legal chars and looking at the rest (needs tcsh):
set ok=`echo $field_1 | tr -d '[:lower:][:upper:][0-9]'`
if ($%ok) then
echo $field_1 contains $%ok illegal chars
exit 1
endif
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2006 11:41 PM
06-08-2006 11:41 PM
Re: Troubles with cshell
Have a nice weekend.