HelpNeeder
HelpNeeder

Reputation: 6490

preserve whitespace from find -printf output

I'm reading the file list with fond and outputting it with -printf where I'm basically creating a string separated by newline chars. When I try to loop through this, filenames with whitespace characters in them render as new entry.

How would I read this while preserving the whitespace in filenames?

loop() {
    files=$(find "${base}" -name "*" -printf "%TD%TT|%p\n")

    for string in $files
    do 
        stamp=${string%|*}
        file=${string#*|}

        echo "$stamp - $file"
    done
}

Upvotes: 0

Views: 210

Answers (1)

HelpNeeder
HelpNeeder

Reputation: 6490

Due to shellter's comment, the While loop allowed me to separate the lines into variables:

loop() {
    while read string
    do
        stamp=${string%|*}
        file=${string#*|}

        files_new[$file]=$stamp
    done < <(find "${base}" -name "*" -printf "%TD%TT|%p\n")
}

Upvotes: 2

Related Questions