1

I have this code

for i in $(find pwd) do echo $i done 

the problem is if the file name contains spaces, it prints on a separate line

how can I list all of the files in some directory including files that contains spaces

1
  • 1
    What is wrong with just find pwd? Commented Jun 3, 2013 at 16:28

3 Answers 3

1

This would have the intended effect of your example:

find /path/to/somewhere 

That is, no need to wrap a for loop around it.

But I'm guessing you want something more than just echoing. Perhaps call a script for each file? You can do that with:

find /path/to/somewhere -exec path/to/script.sh {} \; 

where {} will be replaced for each filename found.

Sign up to request clarification or add additional context in comments.

Comments

1

I would use while read for this.

find . | while read i; do echo $i; done;

Edit:
Alternatively, you could just do ls -a1

Comments

-1

here is the solution

IFS=$'\n' for i in $(pwd) do echo $i done 

2 Comments

Why limited to $7? It will fail if the path contain more spaces, right?
The awk solution is a non-solution, as you are only processing the directory name, not the names of the files contained under the directory. While the IFS-based solution works, it only works for file names that don't contain new lines (which are rare, but legal).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.