15 changed files with 1 additions and 273 deletions
@ -1,2 +0,0 @@ |
|||||
*.bak |
|
||||
|
|
@ -1,17 +0,0 @@ |
|||||
#! /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]}" |
|
||||
|
|
@ -1,11 +0,0 @@ |
|||||
#! /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[@]}" |
|
||||
|
|
@ -1,10 +0,0 @@ |
|||||
#! /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[@]}") |
|
@ -1,10 +0,0 @@ |
|||||
#! /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[@]}" |
|
||||
|
|
@ -1,14 +0,0 @@ |
|||||
#! /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[@]}" |
|
||||
|
|
@ -1,41 +0,0 @@ |
|||||
#! /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 |
|
@ -1,9 +0,0 @@ |
|||||
#! /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[@]}" |
|
||||
|
|
@ -1,16 +0,0 @@ |
|||||
#! /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[@]}" |
|
@ -1,34 +0,0 @@ |
|||||
#! /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 |
|
||||
|
|
@ -1,11 +0,0 @@ |
|||||
#! /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[@]}" |
|
||||
|
|
@ -1,6 +0,0 @@ |
|||||
#! /usr/bin/bash |
|
||||
|
|
||||
family=("Marge" "Homer" "Bart" "Lisa" "Maggie") |
|
||||
|
|
||||
echo "Kinder: ${family[@]:2:4}" |
|
||||
echo "Eltern: ${family[@]:0:2}" |
|
@ -1,22 +0,0 @@ |
|||||
#! /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[@]}" |
|
@ -1 +1,2 @@ |
|||||
*.bak |
*.bak |
||||
|
|
||||
|
@ -1,70 +0,0 @@ |
|||||
#!/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: $@" |
|
||||
|
|
Loading…
Reference in new issue