Reputation: 374
I would like to have a script git-repository
that create a github repository, taking one argument
# git-repository <my_repository_name>
I am however unable to include a $@ variable. The expression:
curl -u mygituser https://api.github.com/user/repos -d "{"name":"$@"}"
gives the error
{
"message": "Problems parsing JSON",
"documentation_url": "https://developer.github.com/v3/repos/#create"
}
How to include the $@ variable inside a JSON expression?
Upvotes: 0
Views: 57
Reputation: 295363
Use jq
to safely generate JSON in bash. In this case, since you want a string rather than an array, you should use $*
rather than $@
:
json=$(jq -nc --arg name "$*" '{"name": $name}')
curl -u mygituser https://api.github.com/user/repos -d "$json"
Upvotes: 1