LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 15
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.

Last edited by guarriman; 02-21-2007 at 11:43 AM.
 
Old 02-21-2007, 11:43 AM   #2
asommer
Member
 
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
andrews-mark
Member
 
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

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

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

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


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 08:38 PM.

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