I have a script execute.sh which receive a JSON with a curl call
#!/bin/bash
source getoutput.sh
server="$1"
cmd="$2"
res=$(curl -sS http://$server -X PUT -H "Content-Type: application/json" -d "{ \"command\" : \"$cmd\" }")
when running this ./execute.sh 246.X.X.X:2000 "stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX"
This is working without any errors
but when running this in a while loop
while read id; do
./execute.sh 246.X.X.X:2000 "stop $id"
done < id
it throws parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 6, column 74
Output différences :
Working:
+ source getoutput.sh
+ server=246.X.X.X:2000
+ cmd='stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX'
++ curl -sS http://246.X.X.X:2000 -X PUT -H 'Content-Type: application/json' -d '{ "command" : "stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX" }'
+ res='{
"status" : 200,
"status_message" : "OK",
}'
Not working when using while loop:
+ source getoutput.sh
+ server=246.X.X.X:2000
+ ' cmd='stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX
++ " }'url -sS http://246.X.X.X:2000 -X PUT -H 'Content-Type: application/json' -d '{ "command" : "stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX
+ res='{
"status" : 400,
"status_message" : "Bad Request",
}'
jq version : 1.5 , bash version : 4.3.48
id
file with dos2unix or similar. – Uncle Billy Jun 17 '19 at 20:35jq --arg varname "$value"
to import a shell variable correctly (including correct encoding) intojq
. See thojq
manual. – Kusalananda♦ Jun 17 '19 at 21:37