Steve
Steve

Reputation: 4691

How to read filenames with spaces in Unix array

I have the following line:

for FILE in $(find "${DIR}" -type f -mtime +14 -level 0)

The trouble is if I have a file named "New Document.txt", on the first pass the value of $FILE will be "New" and on the second it will be "Document". How do I get it to keep filenames together?

I am running this in a windows environment, if that makes a difference.

Upvotes: 1

Views: 1625

Answers (1)

Michael Ballent
Michael Ballent

Reputation: 1088

Instead of using a for loop use the while loop

find "${DIR}" -type f -mtime +14 -level 0 |while read FILE
do
  ls -l  "${FILE}"
done

good luck

Upvotes: 3

Related Questions