LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2009, 02:55 PM   #1
Crafttype
LQ Newbie
 
Registered: May 2009
Distribution: Fedora
Posts: 6

Rep: Reputation: 0
bash string matching


Hi,

I've recently added a new mail filter (bash script) to my server. Now I know this sort of thing should be taboo but I just copied and pasted the script not really understanding what it does or at least the language (bash) its written in. I've done some searching on the net to further my understanding of bash and have learned quite a bit. However, I don't understand what this comma is for:

# Are there more than $SPAMLIMIT stars in X-Spam-Level header? :
if $EGREP -q "^X-Spam-Level: \*{$SPAMLIMIT,}" < /var/tempfs/out.$$
then
# Option 1: Move high scoring messages to sideline dir so
# a human can look at them later:
# mv out.$$ $SIDELINE_DIR/`date +%Y-%m-%d_%R`-$$
# mv /var/tempfs/out.$$ /home/spam_drop/`date +%Y-%m-%d_%R`-$$

# Option 2: Divert to an alternate e-mail address:
# $SENDMAIL spamguy@localhost < /var/tempfs/out.$$

# Option 3: Delete the message
rm -f /var/tempfs/out.$$
elif $EGREP -q "^X-Spam-Level: \*{$SPAMLOW,}" < /var/tempfs/out.$$
then
# Low score
mv /var/tempfs/out.$$ /home/spam_drop/`date +%Y-%m-%d_%R`-$$
else
$SENDMAIL "$@" < /var/tempfs/out.$$
fi
...


In the line "if $EGREP -q "^X-Spam-Level: \*{$SPAMLIMIT,}" < /var/tempfs/out.$$".

Thanks in advance!
 
Old 05-26-2009, 05:50 PM   #2
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
In the extended regular expressions used by egrep
{n,}
matches n or more of the preceding item.

So if the variable $SPAMLIMIT contains an integer
\*{$SPAMLIMIT,}
will match a string of literal * at least $SPAMLIMIT long.

e.g.
\*{4,} matches ***** but does not match ***

http://linux.die.net/man/1/egrep
 
Old 05-26-2009, 06:27 PM   #3
Crafttype
LQ Newbie
 
Registered: May 2009
Distribution: Fedora
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks! I should have been looking for egrep syntax. I'm such a noob.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pattern matching in BASH. ccin1492 Programming 8 12-19-2008 11:00 AM
IPTables String Matching on FC5 jwhitehead Linux - Security 2 07-02-2006 12:42 AM
bash script pattern matching thedude2010 Programming 9 06-02-2006 02:39 AM
regular expresions: java: matching lines with out string zymos Programming 1 05-28-2005 09:17 AM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 09:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration