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
help on egrep arund_01 Shell Programming and Scripting 2 05-13-2008 02:26 PM
egrep help Darklight Shell Programming and Scripting 1 04-18-2008 03:34 AM
egrep DNAx86 Shell Programming and Scripting 7 01-18-2008 08:59 AM
Egrep cheat sheet anywhere? Looking for meaning of egrep -c leelm UNIX for Dummies Questions & Answers 2 01-11-2008 03:37 PM
egrep help Vozx Shell Programming and Scripting 2 12-09-2005 10:42 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 11-10-2004
FuzzyNips FuzzyNips is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 5
Egrep Help

I'm writing a small script thats purpose is to validate a single command line argument to make sure it is an integer. Also acceptable are a leading "+" or "-", but no more than one.

Example: "5" "-2" "+4" are all valid

If its invalid I simply print out a message saying so, otherwise I just return the value (I need to remove the leading "+" though).

Here's the code I have so far:


Code:
# Checks for valid number of arguments
# Exits program with return code of 1
if [ $# -ne 1 ]; then
        echo "Invalid number of arguments; supports only one argument"

        exit 1
fi

# Checks for valid argument
echo $1 | egrep -s "^[+|-]?[0-9]+$"

# If argument is valid then return its value
# Exits program with return code of 0
if [ $? -eq 0 ]; then
        # Removes a leading '+' sign if there is one
        tr -d '+' $1
        echo $1

        exit 0
# If argument is invalid then return an error message
# Exits program with return code of 2
else
        echo "Invalid operand: $1"

        exit 2
fi

My problem is that when a valid argument is entered the cursor just moves to the next line and sits there. I'm guessing something must be wrong with my eGrep statement. I'm looking for a + or - 0 or 1 time...followed by one or more numbers...what am I doing wrong?

EDIT: It may be with my translate command sine I've never used it before. I need to delete all +'s in the (valid) argument....how do I do that?

Last edited by FuzzyNips; 11-10-2004 at 03:50 PM..
 

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 08:39 AM.


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