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

Re: translate all sequences of whitespace/underscores to single dashes



2015-08-17 20:27:22 +0900, Jun T.:
> In theory, if we want the same effect as the original code
> (which uses 'tr -s "-"'), we need
> 
> 	${x//[-_[:space:]]##/-}
> 
> so that x='a_-_z' becomes 'a-z' (not 'a---z').
> 
> BTW, the line
> 	mv $f $new_name 2> /dev/null
> in the function clean-filename() is dangerous, because two files
> $f can have the same $new_name, in which case one of them is lost
> (or $new_name may already exist before the function is called).
[...]

Note that zmv accounts for that (and also adds the missing
"--") (and turns on extendedglob).

zmv '*' '${f//[-_[:space:]]##/-}'

-- 
Stephane



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