lundi 8 décembre 2014

find, xargs and mv: renaming files with double-quotes, expansion and bash precedence issue


Ok, I'm simply trying to strip out double-quotes in my filenames. Here's the command I came up with (bash).



$ find . -iname "*\"*" -print0 | xargs -0 -I {} mv {} {} | tr -d \"


The problem is the 'mv {} {} | tr -d \"' part. I think it's a precedence problem: bash seems to be interpreting as (mv {} {}) | tr -d \"), and what I'm left with are both filenames stripped of double-quotes. That's not what I want, obviously, because then it fails to rename the file. Instead, I want the first filename to have the quotes, and the second not to, more like this: mv {} ({} | tr -d \").


How do I accomplish this? I've tried brackets and curly braces, but I'm not really sure what I'm doing when it comes to explicitly setting command execution precedence.



Aucun commentaire:

Enregistrer un commentaire