3

Everyone knows find . -exec foo {} \; and at some point stopped thinking about it. But recently I came back to the question that arose when I first learned it:

Why would anyone choose {} as the placeholder for the path/name?

If you had to specify a syntax, you would maybe use some $ combination like they are used for parameters of variables in a bunch of other languages. Of as a C programmer one could be tempted to use %like in printf. Even @ would feel a natural choice. Or some "free" character without special meaning in that context. But why a pair of curly braces with nothing inside? Braces were always meant to collect something inside. This seems like the oddest idea to me.

I understand that most of the find history seems to be lost in the uncertain, but maybe someone has knowledge of some early tool using curly braces a similar way?

6
  • The text linked to refers to find in UNIX release 7, but the sources for find are available as early as UNIX release 5 (1974?) – Kusalananda Aug 29 '19 at 14:56
  • probably because very few things would normally use {} and, as you say, they imply a container....a container for the filename(s) that find will be inserting into that space. – cas Aug 29 '19 at 15:25
  • 1
    $ in particular would be bad, since it would get confused with shell variables and you'd need to escape it if the placeholder something else followed by the dollar. Though then again, find does use ;, which needs to be escaped from the shell... – ilkkachu Aug 29 '19 at 18:04
  • @ilkkachu I guess that's why it is a common concept in several tools to pass the whole command to be executed as one argument, for example by single quoting the whole command. Who would mind find . -exec 'foo %; bar %'? – Philippos Aug 30 '19 at 7:13
  • 1
    @Philippos, anyone who wanted to run something more complex. Having the command in single string would require find to process some form of quoting (or require always forking a shell to do it). The way it currently works, find doesn't need to do that, the shell running find splits the -exec command to arguments and find just passes those on when starting the command. – ilkkachu Aug 30 '19 at 8:09
-1

The possible reason could be to denote the endless possibilities which can be shunted after find and you would need some symbol in common which would just mean that convergence of the numerous possibilities. So {} denotes just that.

man find however does not have a mention of the reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.