I have this script which I am writing to help my team squash Git commits into the integration branch on the remote. Needless to say my bash scripting is a bit wanting.
First, here is the script:
    #!/usr/bin/env bash
    FEATURE_BRANCH_NAME="$1" &&
    if [ -z "$1" ]; then
      echo "You did not specify a branch name."
      exit 1;
    fi
    if [${1} == "--force"]; then     # the problem seems to happen here!
      echo "You did not specify a branch name."
      exit 1;
    fi
    if [ "$2" != "--force" ]; then
      echo "Are you sure you want to squash commits for branch name = $FEATURE_BRANCH_NAME? If so use --force."
      exit 1;
    fi
    git fetch origin &&
    git checkout -b temp_branch origin/integration &&
    git merge -Xtheirs --squash -m "squashed with branch=$FEATURE_BRANCH_NAME" $FEATURE_BRANCH_NAME &&
    git checkout $FEATURE_BRANCH_NAME &&
    git merge temp_branch &&
    git push origin $FEATURE_BRANCH_NAME
    #end
The problem I am seeing is that if I execute the above script like so:
./script.sh $(git rev-parse --abbrev-ref HEAD)
then bash tries to actually execute the command represented by the value of $(git rev-parse --abbrev-ref HEAD), (which is the current branch name).
So in other words, if the output of $(git rev-parse --abbrev-ref HEAD) is "xyz_branch", then bash will try to run $ xyz_branch, and bash will spit out:
[xyz_branch: command not found
Above the in script there is a comment # which specifies which line this happening on. What the heck is going on?
 
    