-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):

@Volker Siegel: Your edit might have happened in good intent, but I checked my current find-manual and your corrections are wrong, You also missed the opportunity to summarize your edits which is a bad habit, So I roll your changes back. Sorry, fellow.
– user unknownNov 10 '18 at 23:31

Oh, thank you for rolling it back if it broke something. I was remembering that the text compiler which generates the man page format used to generate these "typographical quotes" as an artifact of the rendering definition. It can also render to TeX for perfect printout formatting. I noticed the quotes because they confused the syntax highlighting. I assumed the that the unusual first quote is wrong when used in code, and still assume that. Note that the two changes were in description text, not code. So if we see them as typography - aesthetical rendering - they are right.
– Volker SiegelNov 11 '18 at 5:30

Looks like in the info output rendering, the same quote is used on both sides. There is no doubt my change made it different from the original, you are right. But has it caused any problem? (I consider the first quote as a bug in the man rendering definition, it's the only case of typography as far as I know.)
– Volker SiegelNov 11 '18 at 5:43

I just checked: `{}' does not work on the command line. That's technically correct, but I do not like it that an unsuspecting user gets a strange error when he tries to copy and paste it.
– Volker SiegelNov 11 '18 at 5:55

@VolkerSiegel: It is prose text, not code, so what shall a user copy-paste here? And it is a citation of the man page from 2011. I don't see any value correcting the passage to then point out, why I made corrections to the man page. The topic is complicated enough. If this was your question, I wouldn't try to convince you, to cite the man page accurately but for my question, I'm not in the mood of doing compromises. Citation is citation.
– user unknownNov 11 '18 at 21:57

3 Answers
3

Summary: If there ever was a shell that expanded {}, it's really old legacy stuff by now.

In the Bourne shell and in POSIX-compliant shells, braces ({ and }) are ordinary characters (unlike ( and ) which are word delimiters like ; and &, and [ and ] which are globbing characters). The following strings are all supposed to be printed literally:

$ echo { } {} {foo,bar} {1..3}
{ } {} {foo,bar} {1..3}

A word consisting of a single brace is a reserved word, which is only special if it is the first word of a command.

Ksh implements brace expansion as an incompatible extension to the Bourne shell. This can be turned off with set +B. Bash emulates ksh in this respect. Zsh implements brace expansion as well; there it can be turned off with set +I or setopt ignore_braces or emulate sh. None of these shells expand {} in any case, even when it's a substring of a word (e.g. foo{}bar), due to the common use in arguments to find and xargs.

In some historical systems, the curly braces are treated as control operators. To assist in future standardisation activities, portable applications should avoid using unquoted braces to represent the characters themselves. It is possible that a future version of the ISO/IEC 9945-2:1993 standard may require that { and } be treated individually as control operators, although the token {} will probably be a special-case exemption from this because of the often-used find{} construct.

This note was dropped in subsequent versions of the standard; the examples for find have unquoted uses of {}, as do the examples for xargs. There may have been historical Bourne shells where {} had to be quoted, but they would be really old legacy systems by now.

The csh implementations I have at hand (OpenBSD 4.7, BSD csh on Debian, tcsh) all expand {foo} to foo but leave {} alone.

That was bash (see $BASH_VERSION). Brace expansion is very much alive and well.
– geekosaurMar 5 '11 at 20:18

2

That was the point. The {} syntax originated in csh, but {} expanded to the empty string. Newer shells recognize that that's nonsensical, but there are still some old cshs out there.
– geekosaurMar 5 '11 at 20:47

1

@geekosaur: Can you say which specific csh-version on which specific platform? I would prefer to test it myself (if it is possible on linux) or be assured, that the person testet it himself.
– user unknownMar 5 '11 at 22:30

1

@geekosaur, {}foo would expand to foo, but {} would expand to {} (except when within backticks, but quoting would not help) and was documented as such. I verified it for the csh of 2BSD (first release), 2.79BSD, 2.8BSD and 2.11BSD.
– Stéphane ChazelasDec 6 '15 at 22:05

Those are probably not the shells the authors of that GNU find documentation had in mind when they wrote that text since fish was first released in 2005 (while that text or similar was already there in 1994) and rc was not originally a Unix shell.

There are some rumors of some versions of csh (the shell that introduced brace expansion) requiring it. But it's hard to give credit to those since the first release of csh in 2BSD didn't. Here as tested in a PDP11 emulator:

Nice to hear, but I'm asking for the opposite, a shell for which doesn't handle it sanely.
– user unknownMar 5 '11 at 15:49

You're assuming that someone would go in and rip out the info page's reference to extra quoting just because Linux systems all have newer csh. Not everyone runs GNU utilities on Linux; in fact it's quite common to install them on older commercial Unix systems whose bundled commands are limited. (Replacing csh on those systems is less likely, because system scripts may rely on the idiosyncrasies of the original csh, and even if users were all configured to use a newer csh, root would almost certainly need to remain the bundled version.)
– geekosaurMar 5 '11 at 15:55

2

No. I'm in a debate with a guy who says, that in our wiki we should give the advice to use "{}" all the time, because the man page says so. And now I would like to know if there is a shell I'm not using, like ksh, zsh, tcsh, csh or XYZsh which I don't know, for which this claim is true, or whether I honestly can assume, that there isn't. If there are shells for different Unixes which need the "{}", that would be a fine explanation why the sentence is still in the man page, but not appropriate as advice for linux beginners.
– user unknownMar 5 '11 at 19:14

Now I'm wondering if pdksh does the right thing... although the correct answer to that is probably "real ksh is FOSS these days".
– geekosaurMar 5 '11 at 19:26

4

Pdksh, like mksh, ksh93, bash and zsh, only expands braces when there's a comma in between (or .. for ksh93, bash and zsh). Only (t)csh expands {foo} to foo, and even it leaves {} alone (at least on recent BSD's).
– GillesMar 5 '11 at 20:42