summaryrefslogtreecommitdiffhomepage
path: root/bash.html.markdown
diff options
context:
space:
mode:
authorMartin Nicholson <recyclebing+github@gmail.com>2018-01-16 16:03:13 +0000
committerMartin Nicholson <recyclebing+github@gmail.com>2018-01-16 16:03:13 +0000
commit8d2055483e8c0a8147414f4695a7cf3e5ede819e (patch)
tree6fc9fb4dd038387c459bb57fe04859b8fe6dfae9 /bash.html.markdown
parent462f94b967d4814e57bb6836cfd9d13abd8f9ab7 (diff)
Added section for =~ operator
Diffstat (limited to 'bash.html.markdown')
-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