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
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?

I have a such conditional:

SPAMH="it is SPAM"
if grep -q $SPAMH $NMDIR/$mail; then

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..
Sponsored Links
Old 11-29-2007
Ygor's Avatar
Ygor Ygor is offline Forum 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
Old 11-29-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Join Date: Dec 2003
Last Activity: 28 February 2015, 10:37 AM EST
Location: /dev/ph
Posts: 4,890
Thanks: 68
Thanked 445 Times in 413 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 03: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 12:44 PM
Pass variable to sql killboy Shell Programming and Scripting 3 08-02-2009 06:17 AM
How to pass a variable to Awk ? Raynon Shell Programming and Scripting 24 02-26-2007 09:25 AM
Pass variable to sed? kristy Shell Programming and Scripting 2 04-04-2002 03:14 PM

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