Browse Source

for/if/while: add

Denis Sokolov 9 years ago
parent
commit
27cc01819f
3 changed files with 33 additions and 0 deletions
  1. 11 0
      pages/common/for.md
  2. 11 0
      pages/common/if.md
  3. 11 0
      pages/common/while.md

+ 11 - 0
pages/common/for.md

@@ -0,0 +1,11 @@
+# for
+
+> Shell loop over parameters
+
+- Perform a command with different arguments.
+
+`for argument in 1 2 3; do {{command $argument}}; done`
+
+- Perform a command in every directory.
+
+`for d in *; do (cd $d; {{command}}); done`

+ 11 - 0
pages/common/if.md

@@ -0,0 +1,11 @@
+# if
+
+> Simple shell conditional
+
+- Echo a different thing depending on a command's success.
+
+`{{command}} && echo "success" || echo "failure"`
+
+- Full if syntax.
+
+`if {{condition}}; then echo "true"; else echo "false"; fi`

+ 11 - 0
pages/common/while.md

@@ -0,0 +1,11 @@
+# while
+
+> Simple shell loop
+
+- Read stdin and perform an action on every line.
+
+`while read line; do echo "$line"; done`
+
+- Execute a command forever once every second.
+
+`while :; do {{command}}; sleep 1; done`