for i in `find *` breakdown since the directory name has space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting for i in `find *` breakdown since the directory name has space
# 1  
Old 12-09-2008
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  
Old 12-09-2008
One way
Code:
find . -name index.html | while read FILENAME
do
      echo "${FILENAME}"
done

# 3  
Old 12-09-2008
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  
Old 12-09-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find and get a file in an entire directory with an excluded directory specified?

How to get a file 'zlib.h' in an entire directory with an excluded directory specified lives under that starting directory by using find command, as it failed on: $ find . -name 'zlib.h' -a -ipath 'CHROME.TMP' -prune -o -print it'll just list entirely up (2 Replies)
Discussion started by: abdulbadii
2 Replies

2. Shell Programming and Scripting

Find every directory named XYZ under the DVLP directory

I only want to find files under each branch of the directory tree inside directories named XYZ and there are multiple XYZ directories? (7 Replies)
Discussion started by: emc^24sho
7 Replies

3. UNIX for Dummies Questions & Answers

Find command fails when a space is in the directory path variable

I have a script like this running under OS X 10.8. The problem arises when the find command encounters a space in the path name. I need the "dir" variable as I'll be extending the script to more general use. #!/bin/bash CFS=$IFS IFS=$(echo) set dir = "/Users/apta/Library/Mail\... (3 Replies)
Discussion started by: apta
3 Replies

4. UNIX for Dummies Questions & Answers

Display all directory/sub directory with occupied space?

Hello, I am using Red Hat linux system. I see my /work directory has used space 300GB. But there are so many sub directory under /work. I want to list each direcotry and under all subdirectory. But i want to know how much space occupied by each directory. What kind of command i can use to... (3 Replies)
Discussion started by: govindts
3 Replies

5. Solaris

How do I breakdown the Target (tx) part of a cXtXdX Iscsi device?

Hello, I am trying to breakdown the cXtXdX (specifically tX) part of an iscsi device. I know in the fibre SAN world, this tX will usually be a combination of the path to device/device WWN. From what I understand in iscsi world it is similar, breaking down into... (0 Replies)
Discussion started by: Bashful
0 Replies

6. Shell Programming and Scripting

find the free space of a particular directory

Hi Guys, I want to find the free space of a particular directory,, Regards, Magesh (3 Replies)
Discussion started by: mac4rfree
3 Replies

7. UNIX for Dummies Questions & Answers

How to find the free space & usage of the particular directory in Hp-Unix?

How to find the free space & usage of the particular directory in Hp-Unix? I want to see the usage in % (2 Replies)
Discussion started by: bobprabhu
2 Replies

8. AIX

aix memory breakdown

Hi, Stats: AIX 5.3, P590 series. 8 CPUs, 27GB RAM. DB SGA 4GB MAXCLIENT=MAXPERM% = 20% (MIN IS 10%) lru_file_repage =1 strict value for maxperm and for maxclient both set to 1. File system=jfs2. paging = 1% all the time (means no paging) Consider the following at point in time: From... (1 Reply)
Discussion started by: shahidsa
1 Replies

9. Shell Programming and Scripting

sed command breakdown

sed -n '/\{10\}E/p' $filename | sort >> $filename.sorted Could somebody please give me a breakdown of what exactly each part of this sed statement does, I have inherited a production script, and know that basically it sorts a file that looks like this (20 spaces here) ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

10. UNIX for Advanced & Expert Users

Space in the directory name

I've got a small script that deletes all the trash from mailusers Trash directory. I run this script once in a while to make some space. (We have lots of IMAP users, who keep their mail on server!) Occansionaly, the users create directories with space in the name (e.g. "My Mail"). And sometimes... (5 Replies)
Discussion started by: nitin
5 Replies
Login or Register to Ask a Question