I'm trying to create a bash function that will use a simple file such as
sample.txt
start=22 Mar 2016 10:00
end=22 Mar 2016 12:09
...and find files that I have installed to /usr/local within the time range as specifed by start and end.
The function I created originally is:
function findInstalled () {
  if [[ $# -ne 1 ]]; then
    echo "[ERROR] Usage: findInstalled /path/to/file" ;
    return 1;
  fi
  start=$( grep start $1 | cut -d'=' -f2 ) ;
  end=$( grep end $1 | cut -d'=' -f2 ) ;
  if [[ ! -z $start ]]; then
    start="-newerct \"${start}\"" ;
  fi
  if [[ ! -z $end ]]; then 
    end="! -newerct \"${end}\"" ;
  fi
  echo find /usr/local $start $end -type f ;
  find /usr/local $start $end -type f ;
}
..and executing the function gives the following output:
$ findInstalled /path/to/sample.txt
find /usr/local -newerct "22 Mar 2016 10:00" ! -newerct "22 Mar 2016 12:09" -type f
find: I cannot figure out how to interpret `"22' as a date or time
The actual execution of the command gives the error ...cannot figure out how to interpret....  However, if I copy and paste the echo'ed version of the command it executes successfully.  Any idea what the problem is?  Note, I've tried with--and without--all kinds of different combinations of double qoutes and single qoutes and none of them have worked.
I have gotten the function to work, although not quite in the way that I wanted, by doing the following instead:
function findInstalled () {
  if [[ $# -ne 1 ]]; then
    echo "[ERROR] Usage: findInstalled /path/to/file"
    return 1;
  fi
  start=$( grep start $1 | cut -d'=' -f2 ) ;
  end=$( grep end $1 | cut -d'=' -f2 ) ;
  find /usr/local -newerct "$start" ! -newerct "$end" -type f ;
}
So, using this, I have managed to achieve my original goal, but I'm dying to find out why my original function does not work, or if it is even possible.
