While trying my hand at writing some bash scripts I've come across various usage of the -exec parameter. In my context, I'm using it after the find command.
This guide states to use {} /; after the exec in order to pass the file name and to escape the ; so that command properly terminates.
This forum post shows the use of '{}' ';' instead of {} /;.
I tried out both methods on Ubuntu 11.04 and only the one with the single quotes is working correctly. Is there a difference between Linux versions which causes this? Are they interchangeable? Is one preferred over the other?
Your shell may assign the sequence
{}
a special meaning (depending on the type of shell and even if you are inside a shell script or not). To avoid this, you may either enclose it in quotes'{}'
or escape it like so:\{\}
(you need to use a backslash\
instead of a forward slash/
like you did in your question).Also note that the usual error message if you do it wrong (for instance, if you use
;
instead of\;
) is:find: missing argument to -exec
See also the corresponding section in
find
's manpage.