title: How to check if file is tar file in Bash shell?
body: <p>My question is about Bash, Shell. I am writing a script and I have the following problem:
  I have a case when user declares that he or she will extract a file into a dir. But I have to test if the existence and if exist a need to check if that file is a *.tar file. I searched for similar like when checking if the file is executable:</p>
  
  <pre><code>if [ -x "file" ]; then
   echo "file is executable"
  else
   echo "file is not executable"
  
  # will this if test work?
  case $1
  "--extract")
   if [ -e $2 ] &amp;&amp; [ tar -tzf $2 &gt;/dev/null ]; then
    echo "file exists and is tar archive"
   else
    echo "file either does not exists or it is not .tar arcive"
   fi
  ;;
  esac
  </code></pre>
  
  <p>Code from above doesn't work it is totally ignored. Any ideas?</p>