0

I am trying to make this commands, which can create a repo in my own github account.

#!/bin/bash
a=$1
curl -u 'MYNAME' https://api.github.com/user/repos -d '{"name":$a}'

But it does not work as I expected. The point is that, how can I pass $1, which is the first argument, into $a.

By the way, this manual code works:

curl -u 'MYNAME' https://api.github.com/user/repos -d '{"name":"NEW_FOLDER"}'

Moreover, if I makes the code like

curl -u 'MYNAME' https://api.github.com/user/repos -d '{"name":"$1"}'

the corresponding folder created will named as -1, which is not what I am looking for.

PS: if I makes the code like

curl -u 'MYNAME' https://api.github.com/user/repos -d '{"name":'"$a"'}'

Then the above turns out to be an error.

shawn:~$ ./gitcp test
Enter host password for user 'MYNAME': 
{
  "message": "Problems parsing JSON",
  "documentation_url": "https://developer.github.com/v3"
}

1 Answers1

2

Replace

'{"name":$a}'

by

'{"name":'\""$a"\"'}'

See: Difference between single and double quotes in bash

Community
  • 1
  • 1
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Thanks @EtanReisner, I did not notice them like that – Eric Renouf Jul 01 '15 at 19:51
  • It does not work. shawn:~$ ./gitcp test Enter host password for user 'MYNAME': { "message": "Problems parsing JSON", "documentation_url": "https://developer.github.com/v3" } shawn:~$ – ArtificiallyIntelligence Jul 01 '15 at 20:18
  • @PabPeter: I've updated my answer. – Cyrus Jul 01 '15 at 20:23
  • My password is correct. But it still says something wrong. Enter host password for user 'MYNAME': { "message": "Validation Failed", "errors": [ { "resource": "Repository", "code": "missing_field", "field": "name" }, { "resource": "Repository", "code": "custom", "field": "name", "message": "name is too short (minimum is 1 characters)" } ], "documentation_url": "https://developer.github.com/v3/repos/#create" } – ArtificiallyIntelligence Jul 01 '15 at 20:30