ini_file_lesen
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| ini_file_lesen [2016/09/23 11:06] – angelegt damian | ini_file_lesen [2020/06/24 14:33] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | =====Werte aus Ini File auslesen===== | ||
| + | |||
| + | ===Bash=== | ||
| <code bash> | <code bash> | ||
| #!/bin/bash | #!/bin/bash | ||
| function readini() { | function readini() { | ||
| - | sections=$(egrep " | + | sections=$(egrep " |
| case $sections in | case $sections in | ||
| 0) | 0) | ||
| Zeile 10: | Zeile 13: | ||
| ;; | ;; | ||
| 1) | 1) | ||
| - | fields=$(($(cat $1 | wc -l) - $(egrep -n " | + | fields=$(($(cat $1 | wc -l) - $(egrep -n " |
| ;; | ;; | ||
| 2) | 2) | ||
| a=0 | a=0 | ||
| - | for sec in $(egrep -n " | + | for sec in $(egrep -n " |
| line[$a]=$sec | line[$a]=$sec | ||
| a=$(($a + 1)) | a=$(($a + 1)) | ||
| Zeile 21: | Zeile 24: | ||
| ;; | ;; | ||
| esac | esac | ||
| - | echo $(egrep -A$fields " | + | echo $(egrep |
| } | } | ||
| # Aufruf: | # Aufruf: | ||
| readini $INI_DATEI $SEKTION $EINTRAG | readini $INI_DATEI $SEKTION $EINTRAG | ||
| + | </ | ||
| + | |||
| + | ===Powershell=== | ||
| + | <code Powershell> | ||
| + | function readini ($file, $section, $entry) { | ||
| + | $seccheck=" | ||
| + | $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=' | ||
| + | if ($_.Substring(0, | ||
| + | $searchcontent=0 | ||
| + | } | ||
| + | $ErrorActionPreference=' | ||
| + | } | ||
| + | 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. | ||
| </ | </ | ||
ini_file_lesen.1474628801.txt.gz · Zuletzt geändert: 2020/06/24 14:33 (Externe Bearbeitung)