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

Re: somehow offtopic: looping filenames



On Mon, Feb 20, 2012 at 11:05:30AM -0800, Bart Schaefer wrote:
> On Feb 20,  7:16pm, meino.cramer@xxxxxx wrote:
> }
> } I habe a loop like this:
> } 
> } for fn *
> } do
> }     flac $fn
> } done
> } 
> } Unfortunately, some file have 'illegal' filenames
> } which parts flac sees as unknown commmand options or as
> } two file and the loop fails.
> 
> Try this:
> 
>     for fn *
>     do
> 	flac $fn:a
>     done
> 
> The :a modifier expands $fn into a full path including removing any
> mentions of "./" and "../".  Think of it as a clean "$PWD/$fn".
> 
> If you don't have a recent-enough zsh for :a to be supported or it is
> for some reason important to avoid the full path, try
> 
> 	flac ${${fn:h}-.}/${fn:t}
> 
> If that's still confusing it because e.g. you have SH_WORD_SPLIT turned
> on, wrap the expression in double quotes.
> 
---end quoted text---

Or:

ls | tr '\n' '\0' | xargs -0 -n 1 flac --

If you're using Gnu xargs then you might need the -r/--no-run-if-empty flag
too.

Steve



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