diff --git a/pages/common/for.md b/pages/common/for.md new file mode 100644 index 00000000000000..2e83b030542bc5 --- /dev/null +++ b/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` diff --git a/pages/common/if.md b/pages/common/if.md new file mode 100644 index 00000000000000..47ca99b5d5a25e --- /dev/null +++ b/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` diff --git a/pages/common/while.md b/pages/common/while.md new file mode 100644 index 00000000000000..053affebbcd0cb --- /dev/null +++ b/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`