19 Commits
1.3 ... 1.5

Author SHA1 Message Date
f7336ae3e6 Merge branch 'develop' 2025-09-15 10:24:16 +02:00
e2346fa32f Aufgeräumt. 2025-09-15 09:50:35 +02:00
ff7035cd22 power.sh für mehrdimensionale Arrays. 2025-09-15 09:37:35 +02:00
4bd2566b04 declare ausgelagert. 2025-09-08 09:33:48 +02:00
0d67903acf array Demos 2025-09-07 14:15:56 +02:00
96f5040dfe append.sh und remove.sh 2025-09-07 11:35:12 +02:00
a48e6bc452 Migrationsscript für /boot/firmware erster Aufschlag. 2025-07-09 17:54:50 +02:00
e64461d64c family_case.sh 2025-06-30 12:56:18 +02:00
dde357c695 Typo 2025-06-19 06:49:21 +02:00
c750cb4c69 Klammernotation beim Parameter. 2025-06-19 06:48:16 +02:00
1af089d106 Verzeichnisse in die korrekte Reihenfolge umbenannt. 2025-06-19 06:24:38 +02:00
dcaafa8604 Umbenennung. 2025-06-19 05:59:08 +02:00
c3f9740332 „teil24/familyif.sh“ hinzufügen
Version mit if
2025-06-17 05:16:31 +00:00
81a7c96f7f teil22 2025-06-16 13:02:22 +02:00
89557b8e36 Revert "„teil23/parseargs.sh“ ändern"
This reverts commit fb7c410e8a.
2025-05-17 12:09:46 +02:00
5d830cbae4 Merge pull request '„teil23/parseargs.sh“ ändern' (#1) from develop into master
Reviewed-on: #1
2025-05-13 12:06:27 +00:00
fb7c410e8a „teil23/parseargs.sh“ ändern 2025-05-13 11:58:31 +00:00
e4190bae83 parseargs.sh 2025-05-12 07:13:05 +02:00
6545189eb0 teil21 2025-03-01 11:07:58 +01:00
24 changed files with 392 additions and 0 deletions

2
arrays/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.bak

17
arrays/access.sh Executable file
View File

@@ -0,0 +1,17 @@
#! /usr/bin/bash
# File: access.sh
# Array of numbers
fib=(0 1 2 3 5 8)
#Array of Strings
family=("Marge","Homer","Bart","Lisa","Maggie")
# outputs only element 0
echo "fib=${fib}"
# output the whole array
echo "fib=${fib[@]}"
#output element by index
echo "fib[4]=${fib[4]}"

11
arrays/append.sh Executable file
View File

@@ -0,0 +1,11 @@
#! /usr/bin/bash
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
echo "Länge family,vorher: ${#family[@]}"
family+=(Herb) # Element anfügen.
echo "family=${family[@]}"
echo "Länge family,nachher: ${#family[@]}"

10
arrays/associative_array.sh Executable file
View File

@@ -0,0 +1,10 @@
#! /usr/bin/bash
declare -A family
family=([father]="Homer" [mother]="Marge" [son]="Bart" [daughter]="Lisa" [baby]="Maggie")
echo "Iterating through associative array using while loop:"
while IFS= read -r key && IFS= read -r value <&3; do
echo "Key: $key, Value: $value"
done < <(printf '%s\n' "${!family[@]}") 3< <(printf '%s\n' "${family[@]}")

10
arrays/create.sh Executable file
View File

@@ -0,0 +1,10 @@
#! /usr/bin/bash
# File: create.sh
a1=(0 1 2 3 4)
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
echo "a1=${a1[@]}"
echo "family=${family[@]}"
echo "Länge family: ${#family[@]}"

14
arrays/declare.sh Executable file
View File

@@ -0,0 +1,14 @@
#! /usr/bin/bash
# File: declare.sh
declare -a sbc
sbc[0]="Raspberry Pi"
echo "Länge sbc: ${#sbc[@]}"
echo "sbc=${sbc[@]}"
sbc[1]="Orange Pi"
echo "Länge sbc: ${#sbc[@]}"
echo "sbc=${sbc[@]}"
sbc[2]="Banana Pi"
echo "Länge sbc: ${#sbc[@]}"
echo "sbc=${sbc[@]}"

41
arrays/iterate.sh Executable file
View File

@@ -0,0 +1,41 @@
#! /usr/bin/bash
# File: iterate.sh
# Array of numbers
fib=(0 1 2 3 5 8)
#Array of Strings
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
# Einfache for Schleife
for name in "${family[@]}"
do
echo "for: name=${name}"
done
echo "---"
# C-ähnliche Schleife im Index
len=${#family[@]}
for ((i=0;i < len; i++));do
echo "for-i: name=${family[i]},i= ${i}"
done
echo "---"
# while Schleife
counter=0
while [ ${counter} -lt ${len} ]; do
echo "while: name=${family[counter]},counter=${counter}"
((counter++))
done
echo "---"
# until Schleife
counter=0
until [ $counter -ge $len ]; do
echo "until: ${family[counter]}"
((counter++))
done

9
arrays/length.sh Executable file
View File

@@ -0,0 +1,9 @@
#! /usr/bin/bash
# File: length.sh
a1=(0 1 2 3 4 5)
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
echo "Größe family: ${#family[@]}"
echo "Größe a1: ${#a1[@]}"

16
arrays/merge.sh Executable file
View File

@@ -0,0 +1,16 @@
#! /usr/bin/bash
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
neighbours=("Ned" "Maude" "Todd" "Rod")
echo "family=${family[@]}"
echo "Länge family: ${#family[@]}"
echo "neighbours=${neighbours[@]}"
echo "Länge neighbours: ${#neigbours[@]}"
merged=(${family[@]} ${neighbours[@]})
echo "merged=${merged[@]}"
echo "Länge merged: ${#merged[@]}"

34
arrays/power.sh Executable file
View File

@@ -0,0 +1,34 @@
#! /usr/bin/bash
# Datei: power.sh
declare -A power
# 1. Zeile (Orange Pi Zero 2W), x-Index: 0
power[0,0]="Orange Pi Zero 2W"
power[0,1]="1,014"
power[0,2]="1,99"
# 2. Zeile (Banana Pi BPI-F3) x-Index: 1
power[1,0]="Banana Pi BPI-F3"
power[1,1]="3,6"
power[1,2]="6,8"
# 3. Zeile (Raspberry Pi 16GB), x-Index: 2
power[2,0]="Raspberry Pi 16GB"
power[2,1]="2,25"
power[2,2]="8,0"
# 4. Zeile (Radxa Zero), x-Index: 3
power[3,0]="Radxa Zero"
power[3,1]="-"
power[3,2]="-"
# 2. Spalte: Stromaufnahme Leerlauf
printf "%-25s %-10s %-10s\n" "SBC" "idle" "load"
for ((x=0; x<4; x++))
do
printf "%-20s %-10s %-10s\n" "${power[${x},0]}" "${power[${x},1]}W" "${power[${x},2]}W"
done

11
arrays/remove.sh Executable file
View File

@@ -0,0 +1,11 @@
#! /usr/bin/bash
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
echo "Länge family,vorher: ${#family[@]}"
unset family[2]
echo "family=${family[@]}"
echo "Länge family,nachher: ${#family[@]}"

6
arrays/slice.sh Executable file
View File

@@ -0,0 +1,6 @@
#! /usr/bin/bash
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
echo "Kinder: ${family[@]:2:4}"
echo "Eltern: ${family[@]:0:2}"

22
arrays/sort.sh Executable file
View File

@@ -0,0 +1,22 @@
#! /usr/bin/bash
family=("Marge" "Homer" "Bart" "Lisa" "Maggie")
neighbours=("Ned" "Maude" "Todd" "Rod")
echo "family=${family[@]}"
echo "Länge family: ${#family[@]}"
echo "neighbours=${neighbours[@]}"
echo "Länge neighbours: ${#neigbours[@]}"
merged=(${family[@]} ${neighbours[@]})
echo "merged=${merged[@]}"
echo "Länge merged: ${#merged[@]}"
# sorting the merged array
sorted=($(printf "%s\n" "${merged[@]}" | sort -n))
echo "sorted=${sorted[@]}"

View File

@@ -0,0 +1,66 @@
#!/usr/bin/bash
# Output colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging-Funktion
log() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check for root privileges
if [ "$EUID" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Create /boot/firmware dir if it doesn't exist
if [ ! -d /boot/firmware ]; then mkdir -p /boot/firmware; fi
# Enable extended globbing for pattern matching
shopt -s extglob
# Copy all files from /boot to /boot/firmware and remove the originals
log "Moving files to /boot/firmware..."
rsync -av --remove-source-files /boot/ /boot/firmware/
# Update the mount point for /boot in fstab to /boot/firmware
log "Updating fstab..."
cp -a /etc/fstab /etc/fstab.bak # create backup
sed -i 's|^\([^#].*\)[[:space:]]/boot[[:space:]]|\1 /boot/firmware |' /etc/fstab
# Sync cache and reboot the system to apply changes
sync
# prompt for reboot
echo ""
while true; do
read -p "Möchtest du das System jetzt neustarten, um die Änderungen zu testen? (J/N): " choice
case $choice in
[Jj]* )
warn "System will be rebooted in 3 seconds"
sleep 2
reboot
;;
[Nn]* )
log "Neustart übersprungen."
log "Bitte starte das System manuell neu, um die Änderungen zu testen."
break
;;
* )
warn "Bitte antworte mit J (Ja) oder N (Nein)."
;;
esac
done
exit 0

1
teil21/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.bak

2
teil21/commandlist.txt Normal file
View File

@@ -0,0 +1,2 @@
s/Simpson/Thompson/
s/Flanders/Flunders/

1
teil21/commands.txt Normal file
View File

@@ -0,0 +1 @@
echo "Hello" | sed 's/Hello/Bye/'

16
teil21/families.txt Normal file
View File

@@ -0,0 +1,16 @@
Simpson, Marge
Simpson, Homer
Simpson, Maggie
Simpson, Lisa
Simpson, Bart
#FLANDERS-START
Flanders, Maude
Flanders, Ned
Flanders, Rod
Flanders, Todd
#FLANDERS-END
Wiggum, Sarah
Wiggum, Clancy
Wiggum, Ralph

0
teil22/ebene0/0.txt Normal file
View File

1
teil23/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.bak

19
teil23/family_case.sh Executable file
View File

@@ -0,0 +1,19 @@
#! /usr/bin/bash
#Datei: teil23/family_case.sh
case ${1} in
'Homer'|'Marge'|'Bart'|'Lisa') # Familie Simpson
echo "Familie Simpson"
;;
'Ned'|'Maude'|'Todd'|'Rod') # Familie Flanders
echo "Familie Flanders"
;;
'Clancy'|'Sarah'|'Ralph') # Familie Wiggum
echo "Familie Wiggum"
;;
*) # default
echo "unbekannte Familie"
;;
esac

12
teil23/family_if.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/bash
# Datei teil23/family_if.sh
if [[ "${1}" == "Homer" || "${1}" == "Marge" || "${1}" == "Bart" || "${1}" == "Lisa" ]]; then
echo "Familie Simpson"
elif [[ "${1}" == "Ned" || "${1}" == "Maude" || "${1}" == "Todd" || "${1}" == "Rod" ]]; then
echo "Familie Flanders"
elif [[ "${1}" == "Clancy" || "${1}" == "Sarah" || "${1}" == "Ralph" ]]; then
echo "Familie Wiggum"
else
echo "unbekannte Familie"
fi

1
teil24/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.bak

70
teil24/parseargs.sh Executable file
View File

@@ -0,0 +1,70 @@
#!/bin/bash
display_help() {
echo "Usage: ${0} [options]"
echo "Options:"
echo " -h, --help Show this help message"
echo " -v, --verbose Enable verbose mode"
echo " -f, --file <file> Specify a file"
echo " -n, --number <num> Specify a number (default: 42)"
}
# Universelle Parameterparser-Funktion
parse_args() {
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
display_help "$@"
exit 0
;;
-v|--verbose)
VERBOSE=true
shift
;;
-f|--file)
if [[ -z "$2" || "$2" == -* ]]; then
echo "Error: --file requires a non-empty argument."
exit 1
fi
FILE="$2"
shift 2
;;
-n|--number)
if [[ -z "$2" || "$2" == -* ]]; then
echo "Error: --number requires a non-empty argument."
exit 1
fi
NUMBER="$2"
shift 2
;;
--) # Explicit end of options
shift
break
;;
-*) # Unknown option
echo "Error: Unknown option $1"
exit 1
;;
*) # Positional argument
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # Restore positional parameters
# Defaults
VERBOSE="${VERBOSE:-false}"
NUMBER="${NUMBER:-42}"
}
# Aufruf der Funktion mit allen Skriptargumenten
parse_args "$@"
# Beispielnutzung
echo "Verbose mode: $VERBOSE"
echo "File: ${FILE:-<not set>}"
echo "Number: $NUMBER"
echo "Positional arguments: $@"