title: bash 'ls' can't find the file after checking that file exists
body: <p>I have this simple code</p>
  
  <pre><code>#!/bin/bash
  
  TIMEOUT=60
  
  # call a function that creates a file
  LOG_FILE_NAME="/dir/something.txt"
  create_a_file(LOG_FILE_NAME)
  
  until [ ! -f ${LOG_FILE_NAME} ] || [ "$TIMEOUT" == "0" ]
  do
      echo "Slept 1 second while waiting for file creation"
      sleep 1
      ((TIMEOUT--))
  done
  
  for file in $(ls -tr /dir/*.txt); do
      #something
  done
  </code></pre>
  
  <p>Most times this works but sometimes I get:
  <code>ls: cannot access /dir/*.txt: No such file or directory</code></p>