0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I actually had to put quotes around the parameter also. -- "{\"name\":\"$@\"}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.