Anonymous Anonymous - 2 years ago 191
Bash Question

How do I fix my shell script for this curl command

Hey guys I'm running a shell script through a few loops to acquire records but the curl command is giving me an invalid json error, what am I doing wrong?

resp=$(curl -g -u "${usr}":"${pwd}" -X GET "${env}"/"${name}"/res/"${type}"?where={%22timestamp%22:{%22$gt%22:{%22$date%22:%22"${date1}"%22},%22$lt%22:{%22$date%22:%22"${date2}"%22}}}&paging=limit:100,page:${i})

Answer Source

Quoting hell. printf can help:

url=$(printf '%s/%s/res/%s?where={%%22timestamp%%22:{%%22$gt%%22:{%%22$date%%22:%%22%s%%22},%%22$lt%%22:{%%22$date%%22:%%22%s%%22}}}&paging=limit:100,page:%s' "$env" "$name" "$type" "$date1" "$date2" "$i")

resp=$(curl -g -u "$usr:$pwd" -X GET "$url")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download