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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
quoting in conditional statement 3Gmobile Shell Programming and Scripting 2 08-14-2006 03:14 AM
*.pm globs without quoting, *.pl doesn't. tphyahoo Shell Programming and Scripting 2 06-02-2006 11:37 AM
M4 quoting drives me crazy hindman Shell Programming and Scripting 0 05-26-2006 10:30 AM
Quoting of special characters vibhor_agarwali UNIX for Dummies Questions & Answers 1 01-30-2005 04:58 AM
quoting echo 'it's friday' yls177 UNIX for Dummies Questions & Answers 3 09-19-2002 11:09 PM

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 09-11-2002
Bab00shka Bab00shka is offline
Registered User
  
 

Join Date: Apr 2002
Location: Chesterfield, UK
Posts: 123
Wildcards and quoting

Hi All

In a script, I want a user to enter 4 characters, these can be a mix of letters (uppercase and lowercase) and numbers.

In this example $var represents what the user has entered.

eg $var can be A9xZ, 3DDL, bbHp .........etc

I need to check that the user has only entered characters so I added the following code:

# Check for invalid characters
echo "$var" | grep [^a-zA-Z0-9] >/dev/null
if [ $? -eq 0 ]
then
echo "$var is not valid."
fi

This appears to work ok unless the user enters a wildcard character.

For example if the user enters bin*, the script expands the * and makes $var equal to all files in the current directory which start with bin.

So $var is "bin bindir binary"

My question is how can I process $var literally as "bin*" in the above grep statement?

Thanks for your help
Helen
  #2 (permalink)  
Old 09-11-2002
photon's Avatar
photon photon is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 162
Change this line in your code from:

echo "$var" | grep [^a-zA-Z0-9] >/dev/null

to:

echo "$var" | grep "[:alnum]\{4\}">/dev/null
  #3 (permalink)  
Old 09-16-2002
Bab00shka Bab00shka is offline
Registered User
  
 

Join Date: Apr 2002
Location: Chesterfield, UK
Posts: 123
Wink

Thanks for your reply Photon, I'll give it a try
Closed Thread

Bookmarks

« unix OS | mget »
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 12:52 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