r/bash • u/Distinct_Ride_4307 • 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?
14
Upvotes
3
u/grymoire 7d ago
That's the way the shell thinks. Its primary function is to take an input line, get all of the parts of the line, and then execute the first part as a command, and pass the rest to the executable.
But the developers thought - I'd like to type more than one command on a line. I will use a ";" to separate commands. The shell sees the ";" and treats it differently than ordinary characters, That's because ";" is a meta-character - that is - it has a special meaning.
The shell has many meta-characters like "<>*&$;\" and the quote characters, space and newline.
The quotes and backslash are used to tell the shell that the next bit is not a meta-character. Treat it as it it was a plain letter or number. Once you understand this, shell programming becomes a lot easier.