The UNIX and Linux Forums  

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
sed: delete regex line and next line if blank one71 Shell Programming and Scripting 2 09-18-2008 02:53 AM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 03:54 AM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
how do i strip this line using perl regex. ramky79 Shell Programming and Scripting 1 03-18-2008 09:10 AM
Regex to pick up name from the following including carriage return at end of the line Shakey21 Shell Programming and Scripting 3 07-18-2002 05:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-08-2008
Registered User
 

Join Date: Sep 2008
Posts: 23
testing for regex at command line

hi unixers,

i wonder if someone can tell me how i can check for a regex at the command line?


Code:
if any parameter begins with a special character then
   do this
else
   do that
thanks for your help.
Reply With Quote
Forum Sponsor
  #2  
Old 10-08-2008
Registered User
 

Join Date: Sep 2008
Posts: 23
since i'm still at the top of the list, i thought i would add that i'm using ksh.

thanks for your help.
Reply With Quote
  #3  
Old 10-08-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
Testing a parameter at the command line? Be preciser and clarify what your trying to achieve.

Regards
Reply With Quote
  #4  
Old 10-08-2008
Registered User
 

Join Date: Sep 2008
Posts: 23
sorry about that and thanks for your response Franklin52.

i have a script that has this syntax: script <group_id> <user_name> <regex>

rules:
* the user can enter single or multiple group_ids and/or user_names
* the regex is optional
* group_ids are 5-digit integers
* user_names are can be a combo of chars and integers


because the regex parameter is optional, i want to check if it was added at the command line. further, if the regex was actually added, then i want to use that regex value against a different script that i created:


Code:
if any parameter begins with a special character; then
  run a different script with the regex parameter
else
  do something else
fi
here's as far as i got.. and i admit, it's not far....


Code:
if [ "$*" begins with any of these '[][\\.*$^]/\\&' ]
  ./script2 regex
else
  do something else
fi
thanks
Reply With Quote
  #5  
Old 10-08-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 250
Using getopts would be a better bet imho.
-g group, -u user -r (optional regexp)...that kind of thing.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0