STRING1 == STRING2 (conditional operator)

true if the strings are equal.

Bash also allows using ==, but this operator is not included in POSIX. Use = for POSIX compatibility.

Integers are compared with -eq.

Bash

This operator uses pattern matching within a [[ ... ]] construct.

Examples

Different ways to test if two strings are equal:
1
2
3
4
5
# Bash
test "$name" == "John" && echo "it's John!"
[ "$name" == "John" ] && echo "it's John!"
[[ "$name" == "John" ]] && echo "it's John!"
[[ "$name" == "Jan"* ]] && echo "it's Jan or Jane!"
BashSupport Pro ist eine Bash IDE mit Unterstützung für ==probieren Sie es aus!
© 2020–2024 Joachim Ansorg
Impressum
Datenschutz
Rechtliches