git - Bash shell script error sh: [: missing `]' -
aim:
i'm trying create useful shortcut initializing git repo locally, , simultaneously creating remote repo origin on bitbucket or github. function added .bashrc file in home directory.
here bash function (which yields error):
function initg() { # defaults bitbucket api local api="https://api.bitbucket.org/1.0/repositories/" local data="name=$3&description=$4&is_private=true&scm=git" local remote="ssh://git@bitbucket.org/$2/$3" # use github if specified if [ "$1" == "gh" ]; api="https://api.github.com/user/repos" data='{"name":"$3", "description": "$4"}' remote="git@github.com:$2/$3" fi if [ -z "$api" ] || [ -z "$data" ] || [ -z "$remote" ] || [ -z "$2" ] echo "a parameter missing or incorrect" else curl -x post -u $2 ${api} -d ${data} git init git add . git commit -m "created repo" git remote add origin $remote git push -u origin master fi } the error:
username@computer-name /path/to/local/repo $ initg gh username bash_test desc sh: [: missing `]' sh: [: missing `]' enter host password user 'username': my question:
first, error? secondly, how might improve control flow or structure of script achieve stated goals?
i've got kind of error because didn't use space before ] ex:
if [ "$#" -ne 2]; instead of
if [ "$#" -ne 2 ]; ps: know old question might :)
Comments
Post a Comment