# Compare Two Variables In A Bash Script

You can compare two variables in a bash script with an `if` block like so:

```bash
if [ "$EDITOR" = "$PREFERRED_EDITOR" ]; then
  # do something ...
fi
```

If those variables are equal, then the contents of the `if` block will be executed.

Notice that both variables are wrapped in quotes. This is to avoid a potential syntax error. If the quotes were excluded and one of the variables happened to be unset, then the comparison would evaluate to:

```bash
if [ "vim" = ]; then
  # do something ...
fi
```

That would cause an error, rather than evaluating to false and moving in. Wrapping each in quotes allows an unset variable to turn into an empty string (`""`).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/os/unix/variables/compare-two-variables-in-a-bash-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
