Aco-gt
How to use for loop with filenames containing spaces?
Hi @andreynering ,
Thanks to your advice, it worked perfectly. However, the find part ended up being quite a tricky method.
$ ls documents/pdf_files
a-sample.pdf 'b sample.pdf' 'c sample d.pdf'
$ task sample-for-cmd
task: [sample-for-cmd] ls 'documents/pdf_files/b sample.pdf'
'documents/pdf_files/b sample.pdf'
task: [sample-for-cmd] ls documents/pdf_files/a-sample.pdf
documents/pdf_files/a-sample.pdf
task: [sample-for-cmd] ls 'documents/pdf_files/c sample d.pdf'
'documents/pdf_files/c sample d.pdf'
Explanation
find {{.PDF_PATH}} -type f -name "*.pdf" -print0: Finds all PDF files in the specified path and outputs the filenames separated by a NULL character (\0).
tr '\0' '@': Translates NULL characters (\0) to the @ symbol.
head -c -1: Removes the last character, which is the trailing @.
This command sequence effectively lists the PDF files with @ as the delimiter and removes the unnecessary trailing @.
3 replies