8 Commits
1.1 ... 1.2

Author SHA1 Message Date
Olli Graf
578119d663 scope 2024-09-22 15:15:28 +02:00
Olli Graf
23e7a9090a Scripts zu Rückgabewerte. 2024-09-22 12:16:16 +02:00
48da83fdd3 Script ausführbar gemacht. 2024-09-20 12:52:18 +02:00
82620782b3 Hilfsdatei entfernt 2024-09-20 07:05:47 +02:00
b1065a657e Dateien hochladen nach „teil16“
Scripts zu Funktionen
2024-09-20 05:05:00 +00:00
68a8069739 Readme aktualisiert. 2024-09-20 07:02:27 +02:00
Olli Graf
36837548d2 teil14 2024-09-08 11:33:42 +02:00
Olli Graf
407d7ef5c0 sdcardtester als Scriptbeispiel. 2024-09-08 11:32:48 +02:00
13 changed files with 240 additions and 8 deletions

View File

@@ -3,11 +3,21 @@
Dateien des bash Tutorioals auf raspithek.de
| Kapitel| Beschreibung |
|--------|-------------|
|--------|------------------------|
1 |Einführung |
| 2 |Hello World |
| 3 | exit Codes |
| 4 |Variablen |
| 5 |Verzweigungen|
| 6 |Svhleifen |
| 2 |Prompt |
| 3 |key bindings |
| 4 |Startvorgang |
| 5 |Environmentvariablen |
| 6 |builtins |
| 7 |Dateien |
| 8 |nano |
| 9 |bash Scripting |
| 10 |Variablen |
| 11 |Verzweigungen |
| 12 |Schleifen |
| 13 |Parameter |
| 14 |exit Codes |
| 15 |von der Idee zum Script |
| 16 |Funktionen |

10
teil14/ifexit.sh Executable file
View File

@@ -0,0 +1,10 @@
#! /usr/bin/bash
./sub.sh ${1}
if [ ${?} -eq 0 ]; then
echo "sub.sh erfolgreich"
else
echo "sub.sh fehlgeschlagen"
fi

4
teil14/simpleexit.sh Executable file
View File

@@ -0,0 +1,4 @@
# /usr/bin/bash
echo "Beispiel für exit Code"
exit 2

10
teil14/sub.sh Executable file
View File

@@ -0,0 +1,10 @@
# !/usr/bin/bash
if [ "${1}" == "fail" ]; then
echo " ${0}: failing"
exit 1
fi
exit 0

59
teil15/sdcardtester Executable file
View File

@@ -0,0 +1,59 @@
#! /usr/bin/bash
MOUNTPOINT='/mnt/speedtest'
# number of threads used during testing
nproc=4
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
if [ "${1}" ]; then
DEVICE=${1}
PARTITION=${DEVICE}1
echo "using device ${DEVICE}"
else
echo "using default device ${DEVICE}"
fi
# check if sd card is inserted
if [ -e ${DEVICE} ]; then
echo "card inserted"
else
echo "no sd card found"
exit 2
fi
echo "deleting partion #1"
sfdisk --delete -w ${DEVICE} 1 && sync
echo "creating new ext4 partition"
echo ",," |sfdisk ${DEVICE} && sync
echo "creating ext4 filesystem on ${PARTITION}"
echo "y" |mkfs.ext4 ${PARTITION}
#check if mount point is available, create otherwise
if [ ! -d "${MOUNTPOINT}" ]; then mkdir "${MOUNTPOINT}"; fi
mount -t ext4 "${PARTITION}" "${MOUNTPOINT}"
cd "${MOUNTPOINT}"
echo "preparing tests"
sysbench fileio --file-total-size=8G prepare > /dev/null
# Test with 16K block size, random read/write
echo "run test with 16K block size"
sysbench fileio --file-block-size=16K --file-total-size=8G --file-test-mode=rndrw --threads=$(nproc) run
# Test with 1M block size, random read/write
echo "run test with 1M block size"
sysbench fileio --file-block-size=1M --file-total-size=8G --file-test-mode=rndrw --threads=$(nproc) run
# cleanup the test files
echo "cleaning up test files"
sysbench fileio --file-total-size=8G cleanup
cd - >/dev/null
umount ${PARTITION}

14
teil16/loop-func.sh Executable file
View File

@@ -0,0 +1,14 @@
#! /usr/bin/bash
# File: loop-func.sh
function hallo() {
echo "Hallo 1"
echo "-------"
}
count=1
while [ ${count} -le 4 ]; do
hallo
count=$((${count} + 1))
done

14
teil16/mult-echo.sh Executable file
View File

@@ -0,0 +1,14 @@
#! /usr/bin/bash
# File: mult-echo.sh
echo "Hallo 1"
echo "-------"
echo "Hallo 1"
echo "-------"
echo "Hallo 1"
echo "-------"
echo "Hallo 1"
echo "-------"

13
teil16/param-func.sh Executable file
View File

@@ -0,0 +1,13 @@
#! /usr/bin/bash
# File: param-func.sh
function hallo() {
echo "Hallo ${1}"
}
count=1
while [ ${count} -le 4 ]; do
hallo "${count}"
count=$((${count} + 1))
done

14
teil16/return-value-echo.sh Executable file
View File

@@ -0,0 +1,14 @@
#! /usr/bin/bash
# File: return-value-echo.sh
function square() {
echo $(( ${1} * ${1} ))
}
square "2"
square "4"
square "3"
square "32"

20
teil16/return-value-echo2.sh Executable file
View File

@@ -0,0 +1,20 @@
#! /usr/bin/bash
# File: return-value-echo2.sh
function square() {
echo $(( ${1} * ${1} ))
}
s2=$(square "2")
s4=$(square "4")
s3=$(square "3")
s32=$(square "32")
echo "Das Quadrat von 2 ist ${s2}"
echo "Das Quadrat von 4 ist ${s4}"
echo "Das Quadrat von 3 ist ${s3}"
echo "Das Quadrat von 32 ist ${s32}"

18
teil16/return-value-return.sh Executable file
View File

@@ -0,0 +1,18 @@
#! /usr/bin/bash
# File: return-value-return.sh
function square() {
return $(( ${1} * ${1} ))
}
square "2"
echo "Quadrat von 2 ist ${?}"
square "4"
echo "Quadrat von 4 ist ${?}"
square "3"
echo "Quadrat von 3 ist ${?}"
square "32"
echo "Quadrat von 32 ist ${?}"

33
teil16/scope/scope.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/bash
# File: scope/scope.sh
# Globale Variable
global_var="Ich bin global"
# Funktion mit lokaler Variable
funktion_mit_lokaler_var() {
local local_var="Ich bin lokal"
var_ohne_local="Ich bin lokal ohne local"
global_var="Ich wurde in der Funktion verändert"
echo "Innerhalb der Funktion:"
echo "Globale Variable: ${global_var}"
echo "Lokale Variable: ${local_var}"
}
# Hauptskript
echo "Vor Funktionsaufruf:"
echo "Globale Variable: ${global_var}"
# Funktionsaufruf
funktion_mit_lokaler_var
# Nach Funktionsaufruf
echo "Nach Funktionsaufruf:"
echo "Globale Variable: ${global_var}"
echo "var_ohne_local: ${var_ohne_local}"
# Versuch, auf die lokale Variable zuzugreifen (dies wird fehlschlagen)
echo "Versuch, auf die lokale Variable außerhalb der Funktion zuzugreifen:"
echo "Lokale Variable: ${local_var}"

13
teil16/simple-func.sh Executable file
View File

@@ -0,0 +1,13 @@
#! /usr/bin/bash
# File: simple-func.sh
function hallo() {
echo "Hallo 1"
echo "-------"
}
hallo
hallo
hallo
hallo