How to add a variable into a grep command
Posted
by
twigg
on Server Fault
See other posts from Server Fault
or by twigg
Published on 2012-11-27T10:03:27Z
Indexed on
2012/11/27
11:06 UTC
Read the original article
Hit count: 311
I'm running the following grep command
var=`grep -n "keyword" /var/www/test/testfile.txt`
This work just as expected but I need to insert the file name dynamically from a loop like so:
var=`grep -n "keyword" /var/www/test/`basename ${hd[$i]}`.txt`
But obviously the use of ` brakes this with a unexpected EOF while looking for matching ``' and unexpected end of file
Any ideas of away around this?
© Server Fault or respective owner