title: How can I loop through only .cpp files in the list obtained from "git status"
body: <p>I have a tool to analyse every .cpp file. I am implementing a pre-commit hook to analyse only edited and staged .cpp files in the local git repository before committing the changes. I have a shell script that gets called from the pre-commit hook and currently my following code fails to fetch me changed .cpp files. What is wrong with this script?</p>
  <p>Code:</p>
  <pre><code>files=$(git status --porcelain | cut -b4-)
  for file in $files; do
      if [$file == *.cpp]; then
          echo $file
      fi
  done
  </code></pre>
  <p>Error:</p>
  <pre><code>./build_script.sh: line 23: [build_script.sh: command not found
  ./build_script.sh: line 23: [pre_commit_sqo_tmp/: No such file or directory
  </code></pre>