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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find a file named vijay in a directory using find command amirthraj_12 UNIX for Dummies Questions & Answers 6 10-25-2008 01:37 PM
How to find the free space & usage of the particular directory in Hp-Unix? bobprabhu UNIX for Dummies Questions & Answers 2 06-27-2008 02:05 PM
aix memory breakdown shahidsa AIX 1 01-04-2008 12:38 PM
sed command breakdown hcclnoodles Shell Programming and Scripting 1 09-09-2002 10:35 AM
Space in the directory name nitin UNIX for Advanced & Expert Users 5 10-06-2001 05:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 12-09-2008
patiobarbecue patiobarbecue is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 16
for i in `find *` breakdown since the directory name has space

hey, somebody can help me on this broken script?

for i in `find . -name index.html`;do
echo "$i"
awk '{print $0}' $i
done

the path to index.html has space in it. For example,
./10 October/index.html

then echo "$i" will gives two lines instead of one:
./10
October/index.html

how do I quota the `find ` properly? thanks!
  #2 (permalink)  
Old 12-09-2008
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
One way

Code:
find . -name index.html | while read FILENAME
do
      echo "${FILENAME}"
done

  #3 (permalink)  
Old 12-09-2008
patiobarbecue patiobarbecue is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 16
thanks! works like a charm. for i in 'find ...' is so commonly seen as an example, it seems I should always use the while statement in future.

by the way, "man read", "man while" didn't give me manual of "read", though intuitively it is quite understandable, I would like to see the manual for learning. please give me a reference. thanks.
  #4 (permalink)  
Old 12-09-2008
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
man ksh

See: while list do list done

In this case the input list is coming from a shell read of the pipe (i.e. the output from find). Shell read is also described in "man ksh".

Expanding a long list of files in a "for" command can produce a syntax error because the command line gets too long. My example works with any number of files.
Closed Thread

Bookmarks

Tags
find space, shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0