message以下幾乎可以作業,但不保留屬性中的換行符。
output="$(ls -la /home/john | gpg --armor --encrypt --recipient [email protected])"
curl \
--request POST \
--url https://api.example.net/sendmail \
--header 'Content-Type: application/json' \
--data @- << EOF
{
"subject": "Test",
"message": "$output"
}
EOF
感謝您的幫助!
uj5u.com熱心網友回復:
\n您需要用JSON 字串中的所有換行符替換:
message=${message//$'\n'/\\n}
但是,我建議使用像這樣的實用程式,jq而不是像這樣的臨時代碼。您還需要對字串中的雙引號和反斜杠進行轉義,并將非 ASCII 字符轉換為\u####轉義序列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/471547.html
上一篇:如何洗掉檔案中的重復行?
下一篇:帶sed的while回圈
