Extra characters in bash array -
my temp file.
{"label": "allowed","value": "20863962"} , {"label": "denied","value": "5"} ,
read array.
#read array ifs=$'\r\n' items=($(cat < ./tmp)) # print items echo "${items[@]}"
the output shows this:
{"label": "allowed","value": "20863962"} , {"label": "denied","value": "5"} ,
and final curl command failing.
when run script -x, showing characters in output suspect may causing final curl command fail.
+ echo '{"label": "allowed","value": "20863962"} ,' '{"label": "denied","value": "5"} ,'
note ' ' in echo output.
my final curl command should this:
curl -d '{ "auth_token":"pass", "items": [{"label": "allowed","value": "20863962"} , {"label": "denied","value": "5"}] }' http://lab:3030/widgets/test
to strip "," can like:
json='{"label": "allowed","value": "20863962"} , {"label": "denied","value": "5"} ,' echo ${json%?} # {"label": "allowed","value": "20863962"} , {"label": "denied","value": "5"}
Comments
Post a Comment