Home > Net >  Find and exec - escaping to prevent problems with $ and ` in filenames?
Find and exec - escaping to prevent problems with $ and ` in filenames?

Time:09-06

I am running the following bash script to find and execute an ID3 modification command on all the .mp3 files in my folders

find -name "*.mp3" -exec bash -c 'eyeD3 --to-v1.1 "{}"' \;

It fails on filenames that contain dollar signs and backticks

bash: -c: line 0: unexpected EOF while looking for matching ``'
bash: -c: line 1: syntax error: unexpected end of file

filenames that fail are eg.

08 - Sam Smith - I'm Not The Only One (Feat. A$AP Rocky).mp3 
02 - The Vaccines - Wreckin` Bar (Ra Ra Ra).mp3 

I know these are special characters so need escaping - but how?

CodePudding user response:

You don't need Bash there.

find -name '*.mp3' -exec eyeD3 --to-v1.1 {}  

CodePudding user response:

Most probably you have some characters in file that change character of your command/parameters. Might be that your filename is not recognized as you thought it would be. Remeber: in linux shell problems with spces/special characters never end.
Therefore it would be easier to do it in safer way:

find -name "*.mp3" -print0 | xargs -n 1 -0 eyeD3 --to-v1.1
  • Related