Syntax

Bash Compare Strings Syntax

In Bash, compare strings: checks if strings are equal or empty — [[ "$a" == "$b" ]] [[ -z "$a" ]]

Quick Answer

Syntax
[[ "$a" == "$b" ]] [[ -z "$a" ]]
BashSyntax

Compare Strings

Code example
[[ "$a" == "$b" ]] [[ -z "$a" ]]

Checks if strings are equal or empty.

Learn More

How to compare strings in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash Compare Strings Syntax

Use [[ "$a" == "$b" ]] [[ -z "$a" ]].

Related Syntax References

Frequently asked questions

What is the Bash syntax for compare strings?

Use this pattern: [[ "$a" == "$b" ]] [[ -z "$a" ]]

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify