I am trying to automate github repo creation. Below is my code:
pushtogithub() {
git init
git config user.name "user name"
git config user.email "user email"
git add .
git commit -m "Initial commit"
content=$(curl -s -u githubusername:githubaccesstoken https://api.github.com/user/repos -d '{"name":"$1", "private":true}')
repo=$(jq -r '.ssh_url' <<< "${content}" )
echo $repo created
git remote add origin [email protected]:githubusername/$repo.git
git push -u origin master
}
My github repo is always creating with -1 name.
What I am doing wrong here?
$1is enclosed in single-quotes and won't be expanded. You can change that part into-d "{\"name\":\"$1\", \"private\":true}"for instance-1name. But still I am not getting correct values inrepo. I am getting the literal valueecho jq -r...into it.echoshould be removed from thejqsubshell, I assumed you had put it there to debug your command and forgot to remove it before posting here.