Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Lonely spacecowboy



On Tue, Mar 27, 2007 at 07:53:36PM +0200, meino.cramer@xxxxxx wrote:
> 
> Hi,
> 
>  I _always_ fail with constructions like
> 
>  cat file.txt | while read file
>  do
>      <cmd> "${file}"
>  done
> 
>  when file.txt containing one file per line and
>  a filename looks like:
> 
>     This is an odd filename.txt
>  
>  . Is there one for all cure for such a constellation?
>  Too much space gives me headaches ! ;)
[...]

Should be alright. zsh is even the one shell where you don't
need the quotes around $file.

Maybe your "cmd" is poorly written and can't cope with filenames
containing blanks.

Problems would come for lines that have leading or trailing
blanks or have backslashes.

Try (with GNU xargs)

xargs -d '\n' -n1 cmd < file.txt

Or

for line (${(f)"$(cat file.txt)"}) cmd -- $line

or

while IFS= read -r line; do
  cmd -- $line
done

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author