Richard
Richard

Reputation: 4546

correct syntax for json in github command from terminal

How can I change this curl command to make it work It is something about using the $@ param that github starts complaining

function create_repo(){
  curl -u 'USER' https://api.github.com/user/repos -d '{"name":$@}'
}

It works if I hardcode the param as a string

Upvotes: 0

Views: 51

Answers (1)

Chris
Chris

Reputation: 136910

Your command uses a singly-quoted string, inside which variables are usually not interpolated (though you haven't specified a particular shell).

Try this instead:

function create_repo(){
  curl -u 'USER' https://api.github.com/user/repos -d "{\"name\":\"$@\"}"
}

Note that we use \" instead of ' for our inner quotes because JSON requires double quotes.

Upvotes: 1

Related Questions