How to find string starts with bash

In this article let’s discuss about How to find string starts with bash. Let’s go through the following methods without any delay.

Method 1:

[[ $a == z* ]]   # True if $a starts with a "z" (wildcard matching).
[[ $a == "z*" ]] # True if $a is equal to z* (literal matching).

if [[ "$HOST" =~ ^user.* ]]; then
    echo "yes"
fi

if [[ "$HOST" =~ ^user.*|^host1 ]]; then
    echo "yes"
fi

Hope the above solution works.

Realted Posts : How to compile gcc c code on windows 10