0

我正在尝试使用 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 命令,它可以正常工作!

有什么建议么?

谢谢!

4

2 回答 2

0

如果 URL 中有与号 (&),我会遇到麻烦。这需要在 shell 脚本中转义,而不是在命令行中。

例如:

http://myweb.com/myservlet?asd=1&jkl=2

需要是

http://myweb.com/myservlet?asd=1\&jkl=2
于 2013-02-23T16:56:13.857 回答
0

正如其他人已经指出的那样,很少有事情

  1. 是什么url?需要是变量的实际 url,该变量$url在使用之前具有初始化的值。

  2. 请确保,解析后的完整 url 会导致您需要的实际 URL。为它做一个回声。

于 2012-12-10T17:44:08.537 回答