簡體   English   中英

你如何在 Bash 腳本中傳遞一個變量來卷曲

[英]How Do You Pass a Variable to Curl in Bash Script

你如何在 Bash 腳本中傳遞一個變量來卷曲

我無法使用環境變量讓這個 curl 在 bash 腳本中工作。 API 密鑰在通過變量傳入時會以某種方式被誤解,並且我在提交時遇到身份驗證錯誤。 如果我插入沒有周圍引號的 API 密鑰作為純文本,這很好用。 我嘗試了各種形式的轉義引號和其他組合。 任何幫助都會很棒。

代碼

#!/bin/bash

source .env

curl -X POST https://api.easypost.com/v2/shipments \
  -u "$EASYPOST_TEST_API_KEY": \
  -d 'shipment[to_address][name]=Dr. Steve Brule' \
  -d 'shipment[to_address][street1]=179 N Harbor Dr' \
  -d 'shipment[to_address][city]=Redondo Beach' \
  -d 'shipment[to_address][state]=CA' \
  -d 'shipment[to_address][zip]=90277' \
  -d 'shipment[to_address][country]=US' \
  -d 'shipment[to_address][phone]=8573875756' \
  -d 'shipment[to_address][email]=dr_steve_brule@gmail.com' \
  -d 'shipment[from_address][name]=EasyPost' \
  -d 'shipment[from_address][street1]=417 Montgomery Street' \
  -d 'shipment[from_address][street2]=5th Floor' \
  -d 'shipment[from_address][city]=San Francisco' \
  -d 'shipment[from_address][state]=CA' \
  -d 'shipment[from_address][zip]=94104' \
  -d 'shipment[from_address][country]=US' \
  -d 'shipment[from_address][phone]=4153334445' \
  -d 'shipment[from_address][email]=support@easypost.com' \
  -d 'shipment[parcel][length]=20.2' \
  -d 'shipment[parcel][width]=10.9' \
  -d 'shipment[parcel][height]=5' \
  -d 'shipment[parcel][weight]=65.9' \

根據戈登戴維森將其分解為最小請求的建議,它開始正確發送。 然后我像上面的問題一樣重建了它,無論出於何種原因,它都像魅力一樣。 -x標志在解決此問題時也非常有用,但首先發現它沒有任何本質上的錯誤。 謝謝大家的回復!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM