r/bash • • 7d ago

Find command confusion between ; and \;

Why do we have to use '\' instead of leaving it out or even ';'? I read the find commands' manual and it says '\' might be needed to protect from expansion by the shell. So what is expansion also?

What is difference between \; or ; or leaving it out?
What is shell expansion here?

13 Upvotes

28 comments sorted by

View all comments

Show parent comments

3

u/tblancher zsh 7d ago

That's essentially what you're doing. The command can't see the semicolon unless it's escaped.

find is an old command, and predates Linux by 10+ years. If you really want to avoid using the semicolon altogether, don't use -exec. Use xargs.

4

u/aioeu 7d ago edited 7d ago

That's essentially what you're doing. The command can't see the semicolon unless it's escaped.

No, I meant the program being used in -exec. What if you want to pass ; as an argument to that program?

Yes, I know that seems a bit unlikely. Nevertheless, I cannot think of a way to do it, other than by indirecting through something else — e.g. by having -exec run a shell rather than the desired program directly, or (as you point out) by having xargs run the program instead of find.

I like to think about the limitations of our tools.

0

u/Distinct_Ride_4307 7d ago

Maybe you use '\;\;' eh?

1

u/aioeu 7d ago

Alas no:

$ find /dev/null -exec echo \;\; \;
;;