title: Getting the path to the newest file in a directory with f=$(cd dir | ls -t | head) not honoring "dir"
body: <p>I would like to get file (zip file) from path with this part of code <code>file=$(cd '/path_to_zip_file' | ls -t | head -1)</code>. Instead that I got my .sh file in directory where I am running this file.</p>
  
  <p>Why I can't file from <code>/path_to_zip_file</code></p>
  
  <p>Below is my code in .sh file</p>
  
  <pre><code>file=$(cd '/path_to_zip_file' | ls -t | head -1)
  last_modified=`stat -c "%Y" $file`;
  current=`date +%s`
  echo $file
  
  if [ $(($current-$last_modified)) -gt 86400 ]; then
          echo 'Mail'
  else
          echo 'No Mail'
  fi;
  </code></pre>