title: Unix shells: How to ensure command works against most common shells?
body: <p>I have some java code which uses jsch to connect to our unix servers and run below command.</p>
  <blockquote>
  <p>ls -lt /tempdirectory/ grep -v '^do | grep &quot;$&quot;(date '+%b %e')&quot; | head
  -1 | awk '{print %9}'</p>
  </blockquote>
  <p>Above command shows all files in the /tempdirectory in long format (the first pipe removes directories). From the result it then filters for all files which were created today (I.e. it greps for &quot;Oct 16&quot;).  Since I did ls -lt the files are ordered by time, so when I pipe against head -1 I will get the latest file today. And then the last pipe will print the filename out</p>
  <p>On a normal putty terminal, once I switch to bash shell, and run above command, it will correctly print out the latest file today.</p>
  <p>But the default shell seems to be Bourne (-sh) which the above command will fail (and hence my code will fail)</p>
  <p>Is there a way to create above command that is safe for common shells? I think the main shells I've seen at work are:</p>
  <p>Bourne (sh)
  Bourne again (bash)
  Korn (ksh)</p>