我正在尝试使用curl删除一些对象。我有一个文件中onjects的id列表。 我遍历列表并发出这样的del:
bash -x del.sh tempId.log
+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
+ curl -H 'Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA' -X DELETE https://url/id
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]+ read id
这是脚本
#!/bin/bash
while read id; do
curl -H "Authorization:OAuth 00D30000001FxvA%21AQEAQKkcrruykRDNDapigaEdJXOc4SS_D27o686DScK8pU22BeMsgWVsWJ.Nv0DXimx2zBFKYlAUeDnGgokY2pU8m9xMoe73&apv=1&cshc=0000004qUmq0000001FxvA" -X DELETE https:url/$id
done <$1
但是,如果我在终端上运行相同的curl命令,它可以正常工作!
有什么建议吗?
谢谢!
答案 0 :(得分:0)
很少有事情,正如其他人已经指出的那样
什么是url
?需要是变量$url
的实际网址,其值在使用前已初始化。
请确保解析后的完整网址会导致您需要的实际网址。为它做一个回声。
答案 1 :(得分:0)
如果你在URL中有&符号(&amp;),我就遇到了麻烦。这需要在shell脚本中进行转义,但不能在命令行中进行转义。
例如:
http://myweb.com/myservlet?asd=1&jkl=2
需要
http://myweb.com/myservlet?asd=1\&jkl=2