title: Capture output from git command?
body: <p>I am writing a script to automate setting up new projects for me.</p>
  
  <p>this includes pulling down a github repository.</p>
  
  <p>What I want to do is have some output from my script, then call <code>git clone $repo</code></p>
  
  <p>I want to show the output from that command while it is running, but then when it has run if it has run successfully replace it's output (note just the git commands output, I still want the output from before that to be there) with <code>repository successfully cloned</code> and if failed just leave the output there, and print <code>repository cloning failed</code>.</p>
  
  <p>How can I do this?</p>
  
  <p>Below is my current (rather simple) script.</p>
  
  <pre><code>#! /bin/bash
  
  # -p project name
  
  templateurl="git@bitbucket.org:xxx/xxx-site-template.git"
  
  while getopts ":p:" opt; do #eventually I'll add more options here
  
  case $opt in
    p)
      project=$OPTARG
      ;;
    \?)
      echo "Invalid option: -$OPTARG" &gt;&amp;2
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." &gt;&amp;2
      exit 1
      ;;
  esac
  done
  
  if [ -z "$project" ]; then
      echo "Project name required"
      exit 1
  fi
  
  clear
  echo "|==========================|"
  echo "| New xxx Project Creator  |"
  echo "|==========================|"
  echo "Project: $project"
  
  if [ -d "$project" ]; then
      echo "Directory $project already exists!"
      exit 1
  fi
  
  
  mkdir $project
  if [ ! -d "$project" ]; then
      echo "Failed to create project directory!"
      exit 1
  fi
  
  echo "Cloning xxx Template repository"
  git clone $templateurl $project
  </code></pre>