The man page for GNU find states:
-exec command ; [...] The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell.
That's from the man to find
(GNU findutils) 4.4.2.
Now I tested this with bash and dash, and both don't need to have the {}
being masked. Here is a simple test:
find /etc -name "hosts" -exec md5sum {} \;
Is there a shell, for which I really need to mask the braces? Note, that it doesn't depend upon whether the file found contains a blank (invoked from bash):
find ~ -maxdepth 1 -type d -name "U*" -exec ls -d {} \;
/home/stefan/Ubuntu One
This changes if the found file is passed to a subshell:
find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d {}' \;
ls: cannot access /home/stefan/Ubuntu: No such file or directory
ls: cannot access One: No such file or directory
which can be solved by:
find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "$0"' {} \;
in contrast to:
find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "{}"' \;
/home/stefan/Ubuntu One
but that's not what the man page is talking about, is it? So which shell treats {}
in a different way?
find
quite early in his/her learning process, as it is important. It is harder to understand than other tools. This very question hints to that. He will read the text, and quite possibly copies the{}'` (It is part of the prose, but he may need quotes anyway, and other reasons.) ... – Volker Siegel Nov 14 '18 at 23:39