Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 02-21-2007, 11:41 AM   #1
Registered: Nov 2004
Posts: 101

Rep: Reputation: 15
Shell script: How to include a variable between apostrophes within a command


I'm trying to find some words within my directory and created a text file containing them which is read by my shell script:
var=`cat words.txt`
for i in $var; do
	echo $i
        find -type f -print0 | xargs -r0 grep -F '$i'
But it searches "$i" (dollar sign with 'i'), and not the word. How to do it?

Thank you very much.

Last edited by guarriman; 02-21-2007 at 11:43 AM.
Old 02-21-2007, 11:43 AM   #2
Registered: Mar 2003
Location: North Carolina
Distribution: Gentoo
Posts: 168

Rep: Reputation: 30
Try double quotes around your variable "$i".
Old 02-21-2007, 12:01 PM   #3
Registered: Feb 2007
Location: London
Distribution: debian
Posts: 108

Rep: Reputation: 15
the double quotes interpret shell variables while the single quotes do not

for example, in the bash shell

> x='foobar'
> echo $x
> echo "$x"
> echo '$x'
Old 02-23-2007, 03:12 AM   #4
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
you are searching idividually throught the words file????

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script: redirect to variable va1damar Programming 1 02-05-2007 04:11 PM
Problem with shell script using a variable from a unix command. abefroman Programming 1 05-10-2006 02:14 PM
expanding variable in shell script dipenchaudhary Programming 8 02-08-2006 05:05 PM
Help with shell script, can't show variable stormrider_may Programming 5 01-27-2006 05:22 PM
Odd problem with making a variable the output of a command in a shell script linux=future Programming 3 12-13-2005 09:45 PM

All times are GMT -5. The time now is 06:41 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration