我有一个脚本execute.sh,它通过curl 调用接收JSON
#!/bin/bash
source getoutput.sh
server="$1"
cmd="$2"
res=$(curl -sS http://$server -X PUT -H "Content-Type: application/json" -d "{ \"command\" : \"$cmd\" }")
运行此 ./execute.sh 246.XXX:2000“stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX”时
这是没有任何错误的工作
但是当在 while 循环中运行它时
while read id; do
./execute.sh 246.X.X.X:2000 "stop $id"
done < id
它抛出解析错误:无效字符串:从 U+0000 到 U+001F 的控制字符必须在第 6 行第 74 列进行转义
输出差异:
在职的:
+ 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",
}'
使用 while 循环时不工作:
+ 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版本:1.5,bash版本:4.3.48