Hallo,
ich schreibe gerade ein bash-script (eher ein miniprogramm) das zwei JSON-datei^1 einliest und auswertet mit jq (see: https://wiki.ubuntuusers.de/jq/) .
ich benutze JSON weil die dateien sowohl mit js als auch php und natürlich bash gelesen/geschrieben (eher php und js hier) werden.
meine JSON sehen etwa so aus:
1 2 3 4 5 6 7 8 | { "comment":"kommentar", "backends": { "back1":"/path/to/data.d/back1.backend", "back2":"/path/to/data.d/back2.backend" } } |
1 2 3 4 5 6 7 8 | { "comment":"kommentar", "frontends": { "sub1":["/path/to/data.d/front1.frontend"], "sub2":["/path/to/data.d/front2.frontend" "/path/to/data.d/front3.frontend"] } } |
ich habe es schon geschafft die beiden JSONs in array zu speichern (dynamisch - unten hier um zu zeigen wie statisch aussieht:)
1 2 3 4 5 | myvar_backend_name=("back1" "back2") myvar_backend_path=("/path/to/data.d/back1.backend" "/path/to/data.d/back2.backend") myvar_frontends=("myvar_frontend_sub1" "myvar_frontend_sub2") myvar_frontend_sub1=("/path/to/data.d/front1.frontend") myvar_frontend_sub2=("/path/to/data.d/front2.frontend" "/path/to/data.d/front3.frontend") |
das schwierige ist jetzt das jenachdem was ich als parameter ($1.. = "-f=sub2" & "-s=1") angebe, die bash-miniapp in das array $myvar_frontend_(was ist bei -f) gehen soll und bei index:(was ist bei -s) den string holen muss.
wie mache ich das ? komme hier nicht weiter.
FG PatrickJRed
PS habe auch schon sachen wie
tmp_front="sub2" # von $... mit split tmp_sub=1 # index:1 von sub2 -> "/path/to/data.d/front3.frontend" tmp="myvar_frontend_${tmp_front}" echo ${!tmp[$tmp_sub]}
probiert, nicht geklappt. - es gibt wenn überhaupt nur für index:0 aus
vielen dank für die hilfe