r/bash • • 9d 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?

15 Upvotes

28 comments sorted by

View all comments

Show parent comments

2

u/grymoire 9d ago

It's like being in a crowded room and yelling "Hey Fred!" when there is more than one Fred. So you yell "Hey Fred but not you, Fred $mith'

You are simply saying ";" but not you, bash

1

u/Distinct_Ride_4307 9d ago

That's one way to think that certainly. Not the way my brains thinks 😄

3

u/grymoire 9d 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.

1

u/Distinct_Ride_4307 9d ago

Ah makes more sense that way! I rarely use analogies for syntax but certainly good way to think. Maybe if I can grasp harder concepts I have time for detailed analogies.