title: Bash: Check if file was modified since used in script
body: <p>I need to check in a script if a file was modified since I read it (another application can modify it in between). According to bash manual there is a "-N" test which should report if a file was modified since last read. I tried it in a small script but it seems like it doesn't work.</p>
  
  <pre><code>#!/bin/bash
  file="test.txt"
  echo "test" &gt; $file
  cat $file;
  if [ -N $file ];
      then echo "modified since read";
  else
      echo "not modified since read";
  fi
  </code></pre>
  
  <p>I also tried an alternative way by touching another file and using</p>
  
  <pre><code>if [ "file1" -nt "file2 ];
  </code></pre>
  
  <p>but this works only on a seconds accuracy which may under rare conditions not be sufficient. Is there any other bash-inbuilt solution for this problem or I do really need to use diff or md5sum?</p>