summaryrefslogtreecommitdiffhomepage
path: root/bash.html.markdown
diff options
context:
space:
mode:
authorLumenTeun <anton@lutic.org>2014-08-06 19:30:15 +0100
committerLumenTeun <anton@lutic.org>2014-08-06 19:30:15 +0100
commit3f8dbe8e77ca8b1602a317e218b78df94afd8f66 (patch)
treecd37064e741c344afd5e19bbfc5ec971ee542604 /bash.html.markdown
parent1c2bc08e1979107339dbee545820f340598a0e1d (diff)
&& and || in Bash if statements.
Diffstat (limited to 'bash.html.markdown')
-rw-r--r--bash.html.markdown12
1 files changed, 12 insertions, 0 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 15d1c068..845ebead 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -7,6 +7,7 @@ contributors:
- ["Alexandre Medeiros", "http://alemedeiros.sdf.org"]
- ["Denis Arh", "https://github.com/darh"]
- ["akirahirose", "https://twitter.com/akirahirose"]
+ - ["Anton Strömkvist", "http://lutic.org/"]
filename: LearnBash.sh
---
@@ -81,6 +82,17 @@ fi
echo "Always executed" || echo "Only executed if first command fails"
echo "Always executed" && echo "Only executed if first command does NOT fail"
+# To use && and || with if statements, you need multiple pairs of square brackets:
+if [ $NAME == "Steve" ] && [ $AGE -eq 15 ]
+then
+ echo "This will run if $NAME is Steve AND $AGE is 15."
+fi
+
+if [ $NAME == "Daniya" ] || [ $NAME == "Zach" ]
+then
+ echo "This will run if $NAME is Daniya OR Zach."
+fi
+
# Expressions are denoted with the following format:
echo $(( 10 + 5 ))