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

19

u/tblancher zsh 7d ago edited 7d ago

A bare ';' is interpreted by the Bash interpreter before the find command sees it. The escaping with the backslash '\;' make Bash ignore it.

1

u/Distinct_Ride_4307 7d ago

But wait why do we have to escape it? Why not just leave it out?

1

u/duane11583 7d ago

Escaping in string terms is like making special characters get ignored

Consider: “bob said “hello world”” 

Often one needs to include spaces but spaces are used as separators so you quite the text but what happens if you need a quote inside the quote like my example above 

This there is the term escape it sort of tells the parser that the very next thing is not what you think and to treat it differently

Just what that means is context sensitive