mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Added section for =~ operator
This commit is contained in:
parent
462f94b967
commit
8d2055483e
@ -161,6 +161,16 @@ then
|
|||||||
echo "This will run if $Name is Daniya OR Zach."
|
echo "This will run if $Name is Daniya OR Zach."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# There is also the =~ operator, which tests a string against a Regex pattern:
|
||||||
|
Email=me@example.com
|
||||||
|
if [[ "$Email" =~ [a-z]+@[a-z]{2,}\.(com|net|org) ]]
|
||||||
|
then
|
||||||
|
echo "Valid email!"
|
||||||
|
fi
|
||||||
|
# Note that =~ only works within double [[ ]] square brackets,
|
||||||
|
# which are subtly different from single [ ].
|
||||||
|
# See the appropriate [manual section](http://www.gnu.org/software/bash/manual/bashref.html#Conditional-Constructs) for more on this.
|
||||||
|
|
||||||
# Expressions are denoted with the following format:
|
# Expressions are denoted with the following format:
|
||||||
echo $(( 10 + 5 )) # => 15
|
echo $(( 10 + 5 )) # => 15
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user