LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell script: How to include a variable between apostrophes within a command (https://www.linuxquestions.org/questions/programming-9/shell-script-how-to-include-a-variable-between-apostrophes-within-a-command-531064/)

guarriman 02-21-2007 11:41 AM

Shell script: How to include a variable between apostrophes within a command
 
Hi.

I'm trying to find some words within my directory and created a text file containing them which is read by my shell script:
Code:

#!/bin/bash
var=`cat words.txt`
for i in $var; do
        echo $i
        find -type f -print0 | xargs -r0 grep -F '$i'
done

But it searches "$i" (dollar sign with 'i'), and not the word. How to do it?

Thank you very much.

asommer 02-21-2007 11:43 AM

Try double quotes around your variable "$i".

andrews-mark 02-21-2007 12:01 PM

the double quotes interpret shell variables while the single quotes do not

for example, in the bash shell

Code:

> x='foobar'
> echo $x
foobar
> echo "$x"
foobar
> echo '$x'
$x

-mark

bigearsbilly 02-23-2007 03:12 AM

you are searching idividually throught the words file????

Code:

find . -type f | xargs -n9 grep -f words.txt


All times are GMT -5. The time now is 10:58 PM.