![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| read a variable character by character, substitute characters with something else | vipervenom25 | UNIX for Dummies Questions & Answers | 2 | 06-06-2008 12:18 PM |
| How to extract first column with a specific character | selamba_warrior | Shell Programming and Scripting | 3 | 05-22-2008 02:14 AM |
| How to change a specific character in a file | sdubey | Shell Programming and Scripting | 6 | 02-22-2008 12:30 PM |
| Escaping specific character in awk | brainyoung | Shell Programming and Scripting | 4 | 01-28-2008 10:42 AM |
| How to add character in specific position of a string? | victorlung | Shell Programming and Scripting | 5 | 09-01-2006 07:33 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[csh] checking for specific character ranges in a variable
I want to check if a zip code is valid, using a variable that stores the zipcode. I am not sure how I would do this in a script. I know that simply checking for the numerical range of the number will not work, because '1' would be '00001' in zip code format. I know when I am in shell, I can use wildcards and ranges to find certain files. How would I do something similar in C shell scripting? This following code is my attempt of checking for correct zip code format.
Code:
if ( $zipcode == "[0-9][0-9][0-9][0-9][0-9]" ) then
echo Zip code is in correct format
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
set zipcode=01234 test $zipcode="[0-9][0-9][0-9][0-9][0-9]" && echo Zip code is in correct format || echo NOK |
|
#3
|
|||
|
|||
|
Thanks. So it's not possible to check using the if statement?
|
|
#4
|
|||
|
|||
|
Yes it is but that's your homework
My example show you a basic AND/OR concept. |
|
#5
|
|||
|
|||
|
How come my code in the OP does not work? Is there a different syntax I need for the condition of my if statement?
|
|
#6
|
||||
|
||||
|
Hi.
Quote:
My general suggestion is to avoid csh for scripting if at all possible. I often use tcsh for interactive work, but I use the Bourne shell family for scripting. It makes life far easier for me. See Csh Programming Considered Harmful for details. Best wishes ... cheers, drl |
||||
| Google The UNIX and Linux Forums |