首页 > 解决方案 > 如何在bash中传递带空格的参数?

问题描述

想要传递带有空格的字符串参数,如下所示:

get_post_data()
{
  cat <<EOF
{"incident":{"type":"incident","title":"$1","service":{"id":"123","type":"service_reference"}}}
EOF
}

send_notification()
{
  curl -X POST --header 'Content-Type: application/json' ... -d "$(get_post_data $1)" 'https://api.service.com/incidents'
}

send_notification Hello World!

标签: bashsh

解决方案


推荐阅读