我正在嘗試運行一個腳本,該腳本將獲取 bitwarden 中的用戶串列并將其輸出到名為 bitmembers 的檔案中。
下面是XXXX我的 API 不記名令牌在哪里的腳本
#!/bin/bash
CURL="/usr/bin/curl"
BITHTTP="https://api.bitwarden.com/public/members"
CURLARGS="-X GET"
header='-H "accept: text/plain" -H "Authorization: Bearer XXXX"'
$CURL $CURLARGS $BITHTTP $header > /tmp/bitmembers
以下是我在運行腳本時遇到的錯誤:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: text
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: Bearer
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: XXXX
以下是 curl 命令并確認有效:
curl -X GET "https://api.bitwarden.com/public/members" -H "accept: text/plain" -H "Authorization: Bearer XXXX"
看起來它在標題部分崩潰了。你能指出我遺漏了什么嗎?
uj5u.com熱心網友回復:
我相信問題在于 curl 選項沒有設定在單獨的變數中,因此以下應該解決錯誤:
#!/bin/bash
CURL="/usr/bin/curl"
CURLARGS="-X GET"
BITHTTP="https://api.bitwarden.com/public/members"
header="-H"
accept="accept:text/plain"
auth="Authorization:Bearer XXXX"
$CURL $CURLARGS $BITHTTP $header "$accept" $header "$auth" > /tmp/bitmembers
這個答案似乎是將變數作為選項發送到主 curl 命令的好方法。例子:
CURL_OPTIONS=( -X GET "$BITHTTP" -H "$accept" -H "$auth" )
$CURL "${CURL_OPTIONS[@]}"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/372399.html
上一篇:1中的三個awk呼叫
