需求:使用shell curl发送消息,钉钉机器人消息为Markdown格式,消息中是以空格作为分隔符,想把空格符转化为换行,在钉钉消息中显示一行一行的。
重点为钉钉消息中换行是shell中的两个\n换行符才行
#!/bin/bash
set -x
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
test="CI/CDjieguo: success success"
new=$(echo -e $test|sed "s@ @\\\n\\\n@g")
curl 'https://oapi.dingtalk.com/robot/send?access_token=558e298279264c8f30bfe1f53a62e' \
-H 'Content-Type:application/json' \
-d '{
"msgtype": "markdown",
"markdown": {
"title":"杭州天气",
"text": "'"$new"'"
}
}'