Languages
[Edit]
EN

Bash - compare string variable to another string

0 points
Created by:
Theodora-Battle
528

In this article, we would like to show you how to compare string variable to another string in Bash.

Practical example

In this example, we use == operator to compare two strings inside if statement.

script.sh file:

#!/bin/bash

string='value'

if [ "$string" == "value" ]; then
    echo "The strings are equal."
fi

Run in command line:

./script.sh

Output:

The strings are equal.

See also

  1. Bash - compare number variable to another number

Alternative titles

  1. Bash - compare string to another string value
  2. Bash - compare strings
  3. Bash - two strings comparison
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join