【发布时间】:2022-01-19 05:36:14
【问题描述】:
我的脚本正在使用 github API 创建拉取请求:
./my-script.sh my-repo my-branch
#!/bin/bash
Repo=$1
Branch=$2
cd $Repo
get_data() {
cat <<EOF
{
"title": "PR title",
"head": $Branch,
"base": "development",
"body": "PR description"
}
EOF
}
echo $(get_data) # <----------------- I can see my value of the variable $Branch here
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-d "$(get_data)" \ # <----------------- But here I'm facing "Problems parsing JSON"
-u my_user:my_token \
https://api.github.com/repos/my_user/$Repo/pulls
open https://github.com/my_user/$Repo/pulls
如何正确地将我的变量设置为 curl?
【问题讨论】:
-
函数 get_data 在没有变量的情况下按预期工作
-
用 '? 定义数据`get_data() { cat
-
@Dan_Maff 你是对的。 "head": "$Branch",成功了!
-
@Dan_Maff 随意添加您的答案。我希望我的脚本对某人有用
-
我没有尝试使用撇号。当我将变量用双引号括起来时它起作用了
标签: bash shell curl github-api