Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

how to pass variable to grep?

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 11-29-2007
Ygor's Unix or Linux Image
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 10 November 2014, 6:18 PM EST
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 112 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 Unix and Linux 11-29-2007
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 19 April 2015, 3:24 AM EDT
Location: /dev/ph
Posts: 4,910
Thanks: 68
Thanked 453 Times in 421 Posts
SPAMH='it is SPAM'
grep "$SPAMH" .....
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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:42 AM.