how to pass variable to grep?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to pass variable to grep?
# 1  
Old 11-29-2007
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
# 2  
Old 11-29-2007
Well, you would certainly need to use "$SPAMH", since it has some spaces, but try using set -x to see what's going-on.
# 3  
Old 11-29-2007
SPAMH='it is SPAM'
grep "$SPAMH" .....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

Hello All, Hope you're doing well ! I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted. header_date_14=$(m_dump... (8 Replies)
Discussion started by: ektubbe
8 Replies

2. Shell Programming and Scripting

How to pass variable to a query?

Hi All, How to pass date variable to a query? I have tried the below one , but it's not working. ost.ksh #!/bin/ksh v_date=$1 var=$(sqlplus -s $ORACON <<ENDOFSQL SELECT TO_DATE('$v_date','DD-MON-YYYY'),-1) FROM DUAL; exit; ENDOFSQL ) #End I have executed as below. (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies

3. UNIX for Dummies Questions & Answers

Pass grep's Output to mv?

Hi! I was looking for files to clean out, and I remembered reading somewhere that you could pipe the output of grep to rm. But I prefer to mv stuff to ~/.Trash/ I thought I'd try something like this: ls ~/Library/Preferences/ |grep '.*.\.iTunes\.plist\..*' |xargs -J % mv % ~/.Trash/ I... (12 Replies)
Discussion started by: sudon't
12 Replies

4. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

5. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

Hello again :) Am currently trying to write a function which will delete a record from a file. The code currently looks as such: function deleteRecord() { clear read -p "Please enter the ID of the record you wish to remove: " strID ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

6. Shell Programming and Scripting

Pass variable to SFTP

Hi All, I am using SFTP command to transfer the file. SRC=`pwd` DIG=123 /bin/sftp -B /dev/stdin xyz@abc.net <<:: mput ${SRC}/GGG.${DIG}.tar.gz bye :: The problem is, after entring into sftp command, it is not taking variable values of SRC and DIG. can someone help me... (0 Replies)
Discussion started by: ace_friends22
0 Replies

7. Shell Programming and Scripting

Problem with * when pass into variable.

Hello expert. I have a little problem here. I write a script and stuck some bug to fix. I found the problem was about * and a sample of script is below. line 1 is print * out but line 3 print all name of files in the script's path. (but I want *) I want to contain * in variable... (3 Replies)
Discussion started by: MaYuMi
3 Replies

8. Shell Programming and Scripting

Pass variable to sql

Please help. I got these error. I'm try to pass variable extract from data-file.txt to sql file(select.sql). cat: cannot open select cat: cannot open * cat: cannot open from cat: cannot open user cat: cannot open where cat: cannot open name=$list; #!/bin/bash list=`sed q... (3 Replies)
Discussion started by: killboy
3 Replies

9. UNIX for Dummies Questions & Answers

How To Pass an Array Variable

Hi, I have a master BASH shell script where I define a bunch of variables: $var1=why $var2=is $var3=(this so hard) I would then like to call another shell script and pass these variables to it: $script2 $var1 $var2 $var3 This works fine for var1 and var2. However, var3 is an array,... (9 Replies)
Discussion started by: msb65
9 Replies

10. Shell Programming and Scripting

How to pass a variable to Awk ?

I am trying to pass 2 shell variable's ("START" and "END") define earlier in the script to this awk statement, but i can't seem to pass it on. PLs help. set START = xxxx set END = yyyy set selected_file = `awk '/$START/,/$END/' filename` (24 Replies)
Discussion started by: Raynon
24 Replies
Login or Register to Ask a Question