[Bash] Test whether a string starts with a prefix

Created on November 30, 2026

Use [[ ... ]] with * to match a prefix. The pattern "$prefix"* matches the literal value of prefix followed by any string.

value="documentroot.org"
prefix="document"

if [[ "$value" == "$prefix"* ]]; then
  echo "true"
else
  echo "false"
fi

Output

true
Bash