简体   繁体   English

curl命令无法传递bash参数

[英]curl command unable to pass bash parameter

so I am new to curl and am trying to write a bash script that will I can run that downloads a file. 所以我是curl的新手,我正在尝试编写一个可以运行的bash脚本来下载文件。 So I start off by authentication then make a POST to request a download. 所以我从身份验证开始,然后发出POST请求下载。 I am given a Foo_ID in which I parse using bash and set to a parameter. 我得到一个Foo_ID,我在其中使用bash解析并设置为参数。 I then try to use GET the certain Foo data via a download URL. 然后我尝试通过下载URL使用GET某些Foo数据。 The issue I am having is that whenever I pass in the parameter I parsed from the POST response I get nothing. 我遇到的问题是每当我传入我从POST响应中解析的参数时,我什么也得不到。 Here is an example of what I am doing. 这是我正在做的一个例子。

#!/bin/bash
curl -b cookies -c cookies -X POST @login_info -d "https://foo.bar.com/auth"
curl -b cookies -c cookies -X POST @Foo_info -d "https://foo.bar.com/foos" > ./tmp/stuff.t
myFooID=`cat ./tmp/stuff.t |grep -Po '"foo_id:.*?",'|cut -d '"' -f 4`
curl -b cookies -c cookies "http://foo.bar.com/foo-download?id=${myFooID}" > ./myFoos/Foo1.data

I have echo'd myFooID to make sure it is correct and it is. 我已经回复了myFooID,以确保它是正确的,它是。 I have also echo'd "https://foo.bar.com/foo-download?id=${myFooID}" and it is properly showing the URL I need. 我也回应了“https://foo.bar.com/foo-download?id=${myFooID}”,它正确显示我需要的URL。 Could anyone help me with this like I said I am new to using curl and a little rusty on using bash commands. 任何人都可以帮我这样,就像我说我是新手使用curl和使用bash命令有点生疏。

So I have solved the issue. 所以我解决了这个问题。 The problem was after doing my post for the Foo I didn't give enough time for my foo to be created before trying to download it. 问题是在为Foo做我的帖子之后我没有给你足够的时间来创建我的foo,然后再尝试下载它。 I added a sleep command between both the last two curl commands and now it works perfectly. 我在最后两个curl命令之间添加了一个sleep命令,现在它完美地运行了。 I would like to thank Dennis Williamson for helping me clean up my code wich led me to understanding my issue. 我要感谢Dennis Williamson帮我清理我的代码,这让我理解了我的问题。 I have created a shrine for him on my desk. 我在我的桌子上为他创造了一座神殿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM