Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Shell Curl JSON变量传递_Json_Shell_Curl - Fatal编程技术网

Bash Shell Curl JSON变量传递

Bash Shell Curl JSON变量传递,json,shell,curl,Json,Shell,Curl,我试图从shell脚本和命令行参数执行CURL调用 url=$1 pg=$2 coockie=$3 curl '$url' -H 'sec-fetch-mode: cors' -H 'origin: $url' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleW

我试图从shell脚本和命令行参数执行CURL调用

url=$1
pg=$2
coockie=$3

curl '$url' -H 'sec-fetch-mode: cors' -H 'origin: $url' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36' -H 'content-type: application/json;charset=UTF-8' -H 'accept: application/json, text/plain, */*' -H 'referer: $url' -H 'authority: recruiting.adp.com' -H '$cookie' -H 'sec-fetch-site: same-origin' --data-binary $'{"filters":[{"name":"country","label":"Country"},{"name":"state","label":"State"},{"name":"grp","label":"Job Type"},{"name":"ptitle","label":"Job"}],"results":{"pageTitle":"Search Results","zeroResultsMessage":"We\'re sorry but we have no job openings at this time that match your search criteria. Please try another search.","searchFailureMessage":"Oops\u0021 Something went wrong.  Search has encountered a problem. Try searching again","resultsFoundLabel":"results found","bookmarkText":"Bookmark This","pageSize":"100","sortOrder":"00001000","shareText":"Share","fields":[{"name":"ptitle","label":"Published Job Title"},{"name":"location","label":"Location"},{"name":"position","label":"Position"}]},"pagefilter":{"page": 3},"rl":"enUS"}' --compressed
回显“$url$pg”

但是“pagefilter”:{“page”:3},“rl”:“enUS”}在这个页面属性脚本中,当它是一个数值时,它是工作的,但我希望它像“pagefilter”:{“page”:“$page”},“rl”:“enUS”}”

无法理解为什么它不起作用。我也试着避开双引号


输入类似于/s.sh“URL”3 1234

用双引号/单引号/双引号将变量括起来
“”
将有助于

这将扩展到

curl -d'{"page":"3"}' http://...
或者仅使用单/双qoutes
展开为数字:

curl -d'{"page":'"$page"'}' http://...
将被彻底扩展

curl '-d{"page":3}'
感谢@jschnnase 尝试使用bash-x,发现只有“$pg”接受该值 “pg”、“$pg”和“$pg”不起作用 下面的代码工作正常

url=$1
pg=$2
coockie=$3

curl '$url' -H 'sec-fetch-mode: cors' -H 'origin: $url' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36' -H 'content-type: application/json;charset=UTF-8' -H 'accept: application/json, text/plain, */*' -H 'referer: $url' -H 'authority: recruiting.adp.com' -H '$cookie' -H 'sec-fetch-site: same-origin' --data-binary $'{"filters":[{"name":"country","label":"Country"},{"name":"state","label":"State"},{"name":"grp","label":"Job Type"},{"name":"ptitle","label":"Job"}],"results":{"pageTitle":"Search Results","zeroResultsMessage":"We\'re sorry but we have no job openings at this time that match your search criteria. Please try another search.","searchFailureMessage":"Oops\u0021 Something went wrong.  Search has encountered a problem. Try searching again","resultsFoundLabel":"results found","bookmarkText":"Bookmark This","pageSize":"100","sortOrder":"00001000","shareText":"Share","fields":[{"name":"ptitle","label":"Published Job Title"},{"name":"location","label":"Location"},{"name":"position","label":"Position"}]},"pagefilter":{"page": '$pg'},"rl":"enUS"}' --compressed

嗨,你能把你的curl调用的相关部分放到你的帖子里吗?我已经添加了代码。也许可以用
试试第二个。如果这对我们没有帮助,我们就走错了方向。尝试了所有的方法,但没有成功。只有当我发送静态数字时,它才起作用。那么你传递的变量是错误的。使用
bash-x
执行脚本以检查正在发生的事情。好的,检查一下。谢谢。找到已发布的解决方案。
url=$1
pg=$2
coockie=$3

curl '$url' -H 'sec-fetch-mode: cors' -H 'origin: $url' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36' -H 'content-type: application/json;charset=UTF-8' -H 'accept: application/json, text/plain, */*' -H 'referer: $url' -H 'authority: recruiting.adp.com' -H '$cookie' -H 'sec-fetch-site: same-origin' --data-binary $'{"filters":[{"name":"country","label":"Country"},{"name":"state","label":"State"},{"name":"grp","label":"Job Type"},{"name":"ptitle","label":"Job"}],"results":{"pageTitle":"Search Results","zeroResultsMessage":"We\'re sorry but we have no job openings at this time that match your search criteria. Please try another search.","searchFailureMessage":"Oops\u0021 Something went wrong.  Search has encountered a problem. Try searching again","resultsFoundLabel":"results found","bookmarkText":"Bookmark This","pageSize":"100","sortOrder":"00001000","shareText":"Share","fields":[{"name":"ptitle","label":"Published Job Title"},{"name":"location","label":"Location"},{"name":"position","label":"Position"}]},"pagefilter":{"page": '$pg'},"rl":"enUS"}' --compressed