diff options
[talks/lbs] Added compound commands section to shell slides
1 files changed, 40 insertions, 3 deletions
| -rw-r--r-- | src/talks/linuxgraphy-by-strabo/index.md | 43 |
diff --git a/src/talks/linuxgraphy-by-strabo/index.md b/src/talks/linuxgraphy-by-strabo/index.md index 10b2aea..7342ebf 100644 --- a/src/talks/linuxgraphy-by-strabo/index.md +++ b/src/talks/linuxgraphy-by-strabo/index.md @@ -894,7 +894,19 @@ Most modern shells support a lot of the more defying features of the [Bourne She + `#`: Everything between a # and the end of the line denotes a comment + `#!`: If on the first line of the file, is treated as a [shebang](https://en.wikipedia.org/wiki/Shebang_%28Unix%29), which specifies what interpreter to be used for the script -- compound commands: Shells also often offer more advanced structured, with which to more easily write complex expressions +- compound commands: Structures for flow control + In all examples, `test-command` is any command (or combination with control operators), and logic is based on exit code. + + + conditional + + ``` + if test-command ; then commands-if-true + elif test-command ; then commands-if-true + else commands-if-true + fi + ``` + + elif statements can appear multiple times, both elif and else are optional &&/slide @@ -902,9 +914,34 @@ Most modern shells support a lot of the more defying features of the [Bourne She &&slide -## 3.2. Files and directories +-   + &&lineb1 -&&lineb1 + ``` + case word in (pattern | ...) commands-if-true ;; ... esac + ``` + + Where the beginning brace can be ommited. + Patterns are according to [bash's pattern matching](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Pattern-Matching) + + + loops + + ``` + while test-command; do commands-if-true; done + ``` + + ``` + for name in words...; do commands-if-true; done + ``` + If `in words...` is ommited, positional arguments are used + +&&/slide + + + +&&slide + +## 3.2. Files and directories - `/bin`: main command programs (binaries), used by users - `/etc`: system configuration files |