diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-02-11 15:18:24 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-02-11 15:18:24 +0100 |
commit | 3064926731fdbf3516e496fa1e905278defeccc3 (patch) | |
tree | ef1c1f5162404c58fd6255a243390f5ed2e27f5d | |
parent | 1a79f611169d7ef128f5eb63294ba11807c5feb3 (diff) |
os week 2
-rwxr-xr-x | os1w2/args | 4 | ||||
-rw-r--r-- | os1w2/enkel.txt | 1 | ||||
-rwxr-xr-x | os1w2/func | 13 | ||||
-rwxr-xr-x | os1w2/hello | 3 | ||||
-rw-r--r-- | os1w2/meerdere.txt | 3 | ||||
-rw-r--r-- | os1w2/practicum.md | 109 | ||||
-rwxr-xr-x | os1w2/treesje | 6 |
7 files changed, 139 insertions, 0 deletions
diff --git a/os1w2/args b/os1w2/args new file mode 100755 index 0000000..ef543ad --- /dev/null +++ b/os1w2/args @@ -0,0 +1,4 @@ +#!/bin/sh +for arg in "$@"; do + echo "$arg" +done; diff --git a/os1w2/enkel.txt b/os1w2/enkel.txt new file mode 100644 index 0000000..5b95370 --- /dev/null +++ b/os1w2/enkel.txt @@ -0,0 +1 @@ +hoi diff --git a/os1w2/func b/os1w2/func new file mode 100755 index 0000000..a194988 --- /dev/null +++ b/os1w2/func @@ -0,0 +1,13 @@ +#!/bin/sh +usage() { + echo "$0: usage: $0 -u" + exit 1 +} + +[ -z "$1" ] && usage + +case "$1" in + "-u") id -un ;; + *) usage ;; +esac + diff --git a/os1w2/hello b/os1w2/hello new file mode 100755 index 0000000..0bb7a40 --- /dev/null +++ b/os1w2/hello @@ -0,0 +1,3 @@ +#!/bin/sh +echo "Hello, world!" + diff --git a/os1w2/meerdere.txt b/os1w2/meerdere.txt new file mode 100644 index 0000000..29c5462 --- /dev/null +++ b/os1w2/meerdere.txt @@ -0,0 +1,3 @@ +hoi +hoi2 +hoi3 diff --git a/os1w2/practicum.md b/os1w2/practicum.md new file mode 100644 index 0000000..c7db34d --- /dev/null +++ b/os1w2/practicum.md @@ -0,0 +1,109 @@ +# os1 practicum week 2 + +<!-- deze week is alles POSIX sh :^) --> + +## opdracht 1 + +```bash +#!/bin/sh +echo "Hello, world!" +``` + +## opdracht 2 + +```bash +#!/bin/sh +for arg in "$@"; do + echo "$arg" +done + +``` + +## opdracht 3 + +```bash +#!/bin/sh +usage() { + echo "$0: usage: $0 -u" + exit 1 +} + +usage +``` + +## opdracht 4 + +```bash +#!/bin/sh +usage() { + echo "$0: usage: $0 -u" + exit 1 +} + +[ -z "$1" ] && usage + +case "$1" in + "-u") id -un ;; + *) usage ;; +esac + +``` + +## opdracht 5 + +1. ```bash + $ ./treesje + + a=hallo + + b=42 + + file args + args: POSIX shell script, ASCII text executable + + file func + func: POSIX shell script, ASCII text executable + + file hello + hello: POSIX shell script, ASCII text executable + + file practicum.md + practicum.md: ASCII text + + file treesje + treesje: POSIX shell script, ASCII text executable + $ + ``` +2. Als `$f` niet in dubbele quotes zou staan, en `*` een bestandsnaam zou + vinden met een spatie, zou `file` deze als losse argumenten zien, waardoor + deze waarschijnlijk een "file not found" foutmelding zal geven. +3. Een lijst van bestanden op losse regels +4. `$*` is een variabele die alle positionele argumenten samengevoegd heeft, + terwijl `*` een wildcard is. + +## opdracht 6 + +```bash +$ # 1 +$ echo "hoi" > enkel.txt +$ # 2 +$ (echo "hoi"; echo "hoi2"; echo "hoi3") > meerdere.txt +$ # 3 +$ cat meerdere.txt +hoi +hoi2 +hoi3 +$ # ik zie de inhoud van meerdere.txt +$ # 4 +$ cat enkel.txt meerdere.txt +hoi +hoi +hoi2 +hoi3 +$ # `cat` voegt bestanden samen (concatenate) +$ # 5 +$ t="`cat enkel.txt`" +$ # 6 +$ echo "$t" +hoi +$ # 7 +$ t="`cat meerdere.txt`" +$ echo "$t" +hoi +hoi2 +hoi3 +$ +``` diff --git a/os1w2/treesje b/os1w2/treesje new file mode 100755 index 0000000..de4ed64 --- /dev/null +++ b/os1w2/treesje @@ -0,0 +1,6 @@ +#!/bin/sh -x +a='hallo' +b=42 +for f in *; do + file "$f" +done |