bash regex if condition 1

bash regex if condition

Use following structure:
if [[ $digit =~ [0-9] ]]; then //run if a digit included in $digit string
    echo "$digit is a digit"
else
    echo "oops"
fi

Here is what the above code is Doing:
1. The first line is a conditional statement.
2. The second line is the command to run if the condition is true.
3. The third line is the command to run if the condition is false.

Similar Posts