Do the parenthesis have to be quoted on find command actions?

The example in the book “Linux Command Line” by William Shotts have the syntax for user-defined actions on find command as: -exec command'{}' ';' to prevent expansion in shell but pretty much everywhere I see the syntax as -exec command {} ;. Can anyone explain the difference?

Answer

This answer is slightly misleading. check Kamil Maciorowski’s comment.

The easiest way to find out will be to use echo command. You can check what commands/programs receive after shell expansion.

$  echo {}
outputs: {}

$  echo '{}'
outputs: {}

$ echo {}
outputs  {}

so there is no real difference between them. one can use either way.

In fact one can mix and match all of them in a single command. the find commands “sees” the same thing.

-exec echo {} '{}' {} ;

This isn’t true for the ; though.

$   echo ;
outputs: # nothing

$   echo ';'
outputs: ;

$   echo ;
outputs: ; 

Leave a Reply

Your email address will not be published. Required fields are marked *