EN
Bash - compare string variable to another string
0 points
In this article, we would like to show you how to compare string variable to another string in Bash.
In this example, we use ==
operator to compare two strings inside if
statement.
script.sh
file:
xxxxxxxxxx
1
2
3
string='value'
4
5
if [ "$string" == "value" ]; then
6
echo "The strings are equal."
7
fi
Run in command line:
xxxxxxxxxx
1
./script.sh
Output:
xxxxxxxxxx
1
The strings are equal.