Aco-gt
Aco-gt
TTask
Created by Aco-gt on 8/13/2024 in #help
How to use for loop with filenames containing spaces?
I'm encountering an error when trying to run a Taskfile and need some help. My task needs to process filenames that may contain spaces.
task: Failed to run task "sample-for-cmd": 6:1: "foo(" must be followed by )
task: Failed to run task "sample-for-cmd": 6:1: "foo(" must be followed by )
Here is the relevant part of my Taskfile:
sample-for-cmd:
desc: Sample how to use for cmd
vars:
PDF_PATH: "./my_pdf_path"
DEST_PATH: "./my_dest_path"
MY_VAR:
sh: find {{.PDF_PATH}} -type f -name *.pdf
cmds:
- for: { var: MY_VAR, split: '\t' }
cmd: cp {{.ITEM}} {{.DEST_PATH}}
sample-for-cmd:
desc: Sample how to use for cmd
vars:
PDF_PATH: "./my_pdf_path"
DEST_PATH: "./my_dest_path"
MY_VAR:
sh: find {{.PDF_PATH}} -type f -name *.pdf
cmds:
- for: { var: MY_VAR, split: '\t' }
cmd: cp {{.ITEM}} {{.DEST_PATH}}
However, it doesn't seem to work correctly when filenames contain spaces. I tried using tr to convert null characters to tabs, find {{.PDF_PATH}} -type f -name '*.pdf' -print0 | tr '\0' '\t' but it still didn't work. Does anyone know how to correctly use the for loop with filenames containing spaces in Taskfile? Thanks!
3 replies