=====Werte aus Ini File auslesen===== ===Bash=== #!/bin/bash function readini() { sections=$(egrep "^\[.{0,}\]" $1 | grep -i -A1 "\[$2\]" | wc -l) case $sections in 0) echo "FEHLER" exit 2 ;; 1) fields=$(($(cat $1 | wc -l) - $(egrep -n "^\[.{0,}\]" $1 | grep -i -A1 "\[$2\]" | cut -d ":" -f 1))) ;; 2) a=0 for sec in $(egrep -n "^\[.{0,}\]" $1 | grep -i -A1 "\[$2\]" | cut -d ":" -f 1); do line[$a]=$sec a=$(($a + 1)) done fields=$((${line[1]} - ${line[0]} - 1)) ;; esac echo $(egrep -i -A$fields "^\[$2\]" $1 | egrep -i "^$3=" | cut -d "=" -f 2) } # Aufruf: readini $INI_DATEI $SEKTION $EINTRAG ===Powershell=== function readini ($file, $section, $entry) { $seccheck="[" + $section + "]" $searchcontent=0 $RESULT="" Get-Content $file | ForEach-Object { if ($searchcontent -eq 1) { $read=$_.Split("=") if ($read[0] -eq $entry) { $RESULT=$read[1] $searchcontent=2 } $ErrorActionPreference='SilentlyContinue' if ($_.Substring(0,1) -eq "[") { $searchcontent=0 } $ErrorActionPreference='Continue' } if ($_ -eq $seccheck) { $searchcontent=1 } } Write-Output $RESULT } # Aufruf: readini -file $INI_DATEI -section $SEKTION -entry $EINTRAG # oder readini $INI_DATEI $SEKTION $EINTRAG # Wichtig! Die Werte innehralb der Variablen müssen in Anführungszeichen stehen. Ansonsten krachts.