![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|