how to pass variable to grep? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

how to pass variable to grep?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-29-2007
xist xist is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 29 August 2008, 12:33 PM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
how to pass variable to grep?

Hi
I have a such conditional:


Code:
SPAMH="it is SPAM"
if grep -q $SPAMH $NMDIR/$mail; then
                SPAMHFLAG=1
        else
                SPAMHFLAG=0
fi

And grep doesn't catch this string, even it exists there. I think it's a problem with passing $SPAMH to grep. I tried "$SPAMH", '$SPAMH', `$SPAMH` etc, but it doesn't help.
Please advice me how to make it working..
Thanks
Sponsored Links
    #2  
Old 11-29-2007
Ygor's Avatar
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 2 May 2014, 7:14 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 111 Times in 98 Posts
Well, you would certainly need to use "$SPAMH", since it has some spaces, but try using set -x to see what's going-on.
Sponsored Links
    #3  
Old 11-29-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 16 September 2014, 10:54 AM EDT
Location: /dev/ph
Posts: 4,803
Thanks: 63
Thanked 425 Times in 394 Posts
SPAMH='it is SPAM'
grep "$SPAMH" .....
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to pass value of pwd as variable in SED to replace variable in a script file cielle Red Hat 6 03-28-2012 02:47 AM
How to pass a function with a variable parameter into another variable? U_C_Dispatj Shell Programming and Scripting 2 05-26-2011 11:44 AM
Pass variable to sql killboy Shell Programming and Scripting 3 08-02-2009 05:17 AM
How to pass a variable to Awk ? Raynon Shell Programming and Scripting 24 02-26-2007 08:25 AM
Pass variable to sed? kristy Shell Programming and Scripting 2 04-04-2002 02:14 PM



All times are GMT -4. The time now is 11:27 AM.