寫的升級shell腳本,里面調(diào)用了某些restapi,需要傳header或者body參數(shù),使用shell中定義的變量({xx}形式),發(fā)現(xiàn)不能轉(zhuǎn)換,原因是在單引號里面。
結(jié)論:如果使用變量,得換成雙引號,數(shù)據(jù)里面也有雙引號,加轉(zhuǎn)義字符即可。
最終形式如下:
curl-X POST --header'Content-Type: application/json'--header'Accept: application/json'--header'authtype: local'--header"username: {admin_token}"-d"{"email": "
payment_account", "paymentServer": "
{wx_service_name}", "vendor": "xxx" }" "http://xxxxx.com/api/001api"-w"\nhttp_code=%{http_code}\n"-v -o${result_log} |grep'http_code=200'