我有一个脚本execute.sh,它通过curl 调用接收JSON
\n\n#!/bin/bash\n\nsource getoutput.sh\nserver="$1"\ncmd="$2"\n\nres=$(curl -sS http://$server -X PUT -H "Content-Type: application/json" -d "{ \\"command\\" : \\"$cmd\\" }")\nRun Code Online (Sandbox Code Playgroud)\n\n运行此\n./execute.sh 246.XXX:2000“stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX”时
\n\n这是没有任何错误的工作
\n\n但是当在 while 循环中运行它时
\n\nwhile read id; do\n./execute.sh 246.X.X.X:2000 "stop $id"\ndone < id\nRun Code Online (Sandbox Code Playgroud)\n\n它抛出解析错误:无效字符串:从 U+0000 到 U+001F 的控制字符必须在第 6 行第 74 列进行转义
\n\n输出 diff\xc3\xa9rences :
\n\n在职的:
\n\n+ source getoutput.sh\n+ server=246.X.X.X:2000\n+ cmd=\'stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX\'\n++ curl -sS http://246.X.X.X:2000 -X PUT -H \'Content-Type: application/json\' -d \'{ "command" : "stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX" }\'\n+ res=\'{\n "status" : 200,\n "status_message" : "OK",\n}\'\nRun Code Online (Sandbox Code Playgroud)\n\n使用 while 循环时不工作:
\n\n+ source getoutput.sh\n+ server=246.X.X.X:2000\n+ \' cmd=\'stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX\n++ " }\'url -sS http://246.X.X.X:2000 -X PUT -H \'Content-Type: application/json\' -d \'{ "command" : "stop FXXXXXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX\n+ res=\'{\n "status" : 400,\n "status_message" : "Bad Request",\n}\'\nRun Code Online (Sandbox Code Playgroud)\n\n\n\njq 版本:1.5,\n bash 版本:4.3.48
\n