1

Im trying to create a bash script to make github pull requests here its my code:

Gist Code

I get this error:

curl: (6) Could not resolve host: on
curl: (3) [globbing] unmatched close brace/bracket in column 63
{
  "message": "Problems parsing JSON",
   "documentation_url": "https://developer.github.com/v3"
}

Please help

midori
  • 4,807
  • 5
  • 34
  • 62
bitgandtter
  • 2,179
  • 6
  • 31
  • 60

2 Answers2

2

More/proper quoting:

body=$(printf '{"title":"%s","body":"%s","head":"clamour:%s","base":"%s"}' "$TITLE" "$DESCRIPTION" "$TARGET" "$SOURCE")
curl -H "$auth" -d "$body" "https://api.github.com/repos/clamour/$PROJECT/pulls"

All user-supplied variables must be quoted (unless you know exactly why you want to leave then unquoted). Enclosing a variable name in ${braces} is not the same as "$quoting".

I find using printf tends to be more clear than mixing double and single quotes with variable interpolation.

Get out of the habit of using ALLCAPS variable names: one day you'll use PATH=... and then wonder why your script is broken

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
1

you are using a lot of variables try to do it like this

BODY="{\"title\":\"$TITLE\",\"body\":\"$DESCRIPTION\",\"head\":\"clamour\":\"$TARGET\",\"base\":\"$SOURCE\"}"
"https://api.github.com/repos/clamour/$PROJECT/pulls"

read also this Difference between single and double quotes in Bash

Community
  • 1
  • 1
midori
  • 4,807
  • 5
  • 34
  • 62
  • i test your solution but got the same error, maybe the command line call can bring more light, here it is: sh test.sh -t="jenkins-api-dev-133" -d="7f1bb90659de081eb6070d7a574ec4b89489b6b8 on 2014-11-28_18-48-36" -t_b=staging -s_b=develop -p=project – bitgandtter Nov 28 '14 at 20:27
  • host should be defenetly in double quotes, because you are using variable in the link. For Body part you probably should use escaping, i edited the BODY part. I don't have anything to test on it right now. – midori Nov 28 '14 at 20:28