The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Escaping specific character in awk brainyoung Shell Programming and Scripting 8 12-16-2008 11:14 PM
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 03:18 PM
How to extract first column with a specific character selamba_warrior Shell Programming and Scripting 3 05-22-2008 05:14 AM
How to change a specific character in a file sdubey Shell Programming and Scripting 6 02-22-2008 03:30 PM
How to add character in specific position of a string? victorlung Shell Programming and Scripting 5 09-01-2006 10:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2008
userix userix is offline
Registered User
  
 

Join Date: May 2008
Posts: 21
[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
  #2 (permalink)  
Old 05-11-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
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 (permalink)  
Old 05-11-2008
userix userix is offline
Registered User
  
 

Join Date: May 2008
Posts: 21
Quote:
Originally Posted by danmero View Post
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
Thanks. So it's not possible to check using the if statement?
  #4 (permalink)  
Old 05-11-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Yes it is but that's your homework
My example show you a basic AND/OR concept.
  #5 (permalink)  
Old 05-11-2008
userix userix is offline
Registered User
  
 

Join Date: May 2008
Posts: 21
Quote:
Originally Posted by danmero View Post
Yes it is but that's your homework
My example show you a basic AND/OR concept.
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 (permalink)  
Old 05-11-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi.
Quote:
Originally Posted by userix View Post
How come my code in the OP does not work? Is there a different syntax I need for the condition of my if statement?
My specific suggestion is to look in man csh for "==".

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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0