PDA

View Full Version : Bash: Assigning variables


sjau
17th May 2006, 23:53
Hiya

I have a little code snippet like this:


LINK=`/bin/grep -f http://www.spamcop.net/sc?id= $FILENAME`
echo $LINK
LINK=`/bin/fgrep http://www.spamcop.net/sc?id= $FILENAME`
echo $LINK
LINK=`/bin/ls $FILENAME`
echo $LINK


The output is this:


grep: http://www.spamcop.net/sc?id=: No such file or directory

/bin/fgrep: line 2: exec: grep: not found

1147891663.9720_2.t390.greatnet.de:2,ST
grep: http://www.spamcop.net/sc?id=: No such file or directory

/bin/fgrep: line 2: exec: grep: not found

1147896741.16696_2.t390.greatnet.de:2,ST



Why do grep and fgrep not work but the ls does?

falko
18th May 2006, 20:41
I don't think you can use grep for files that aren't on the same system.

sjau
18th May 2006, 21:10
They are on the same system but I have to use grep -F and not grep -f ^^

But I still wonder why fgrep does not work...

falko
19th May 2006, 15:30
But you can't use grep with URLs, no matter if they point to the same system.

sjau
19th May 2006, 15:35
Not sure what you mean. The shell script looks like this now:


#!/bin/bash

# ENTER PATH OF THE VERIFICATION EMAILS FROM SPAMCOP
PATH="/home/mail/web4p1/Maildir/.Spamcop-Reply/cur"

# ENTER WEBPATH TO PHP SCRIPT
URL="http://www.roleplayer.org/spamcop.php"

################################################## ###############
################################################## ###############

cd $PATH

for FILENAME in *S
do

LINK=`/bin/grep -F http://www.spamcop.net/sc?id= $FILENAME`
echo $LINK
# LINK=`/bin/fgrep http://www.spamcop.net/sc?id= $FILENAME`
# echo $LINK
# LINK=`/bin/ls $FILENAME`
# echo $LINK
# lynx -dump $URL?link=$LINK


# /bin/rm $FILENAME

done

falko
21st May 2006, 21:45
You can use grep with local files, e.g. grep bla /path/to/example.txt, but not with URLs, like grep bla http://www.example.com/example.txt

neil6179
22nd May 2006, 20:07
You could use wget to download the file then pipe it into grep.

wget -q -O - "http://www.example.com/example.txt" | grep bla