summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bash.html.markdown10
1 files changed, 10 insertions, 0 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index fa3c5ebe..354042ec 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -161,6 +161,16 @@ then
echo "This will run if $Name is Daniya OR Zach."
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:
echo $(( 10 + 5 )) # => 15