The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need a sed command that uses variable ketkeep Shell Programming and Scripting 2 06-07-2008 10:36 AM
Question On Command in Variable scotbuff Shell Programming and Scripting 4 10-29-2007 04:23 PM
How to Store command O/P to a variable... smartbuddy UNIX for Dummies Questions & Answers 7 08-24-2007 04:49 AM
set variable command ammu Shell Programming and Scripting 1 05-24-2007 06:45 AM
Export command giving Variable Name vs the Value set for the Variable ParNone UNIX for Dummies Questions & Answers 2 04-03-2006 08:43 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Feb 2007
Posts: 1
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-21-2007
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Quote:
Originally Posted by guarriman
Code:
#!/bin/bash
var=`cat words.txt`
for i in $var; do
	echo $i
        find -type f -print0 | xargs -r0 grep -F '$i'
done
Code:
find -type f -print0 | xargs -r0 grep -F "$i"
Reply With Quote
  #3 (permalink)  
Old 03-16-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
guarriman,
You can try:
ls -1 | egrep -f words.txt
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0