Fohnbit schrieb:
| RESPONSE=$(curl -X POST -H 'Content-Type: application/json' -d $JSON_STRING $URL | jq -r '.name')
|
Also, das muss erst mal so aussehen:
| RESPONSE=$(curl -X POST -H 'Content-Type: application/json' -d "$JSON_STRING" "$URL" | jq -r '.name')
|
Bei "$URL" muss es nicht unbedingt sein - je, nach Zeichen in der URL. Es ist egal, wie viele einfache oder doppelte Anführungszeichen in $JSON_STRING stecken, das wird so korrekt expandiert. Beispiel:
| $ foo='"'
$ args.sh "$foo"
arg count: 1
arg[1]: '"'
$ foo="'"
$ args.sh "$foo"
arg count: 1
arg[1]: '''
|
Das problem ist wohl, das die Variable "JSON_STRING" Hochkommas enthält. Also muss ich den Inhalt zwischen zwei ' ' setzen,
Nein, Du brauchst lediglich doppelte Anführungszeichen (s.o.).
aber dann nimmt er nimmer den Inhalt der Variable:
Es ist nicht der Inhalt sondern der Name!
| $ args.sh '$JSON_STRING'
arg count: 1
arg[1]: '$JSON_STRING'
|
| RESPONSE=$(curl -X POST -H 'Content-Type: application/json' -d '$JSON_STRING' $URL | jq -r '.name')
|
Wie kann man das lösen?
s.o.
Wenn es irgendwo schief geht, dann vielleicht beim Befüllen von $JSON_STRING. Zeige doch mal den Code.