Hi everybody,
I'm writing a bash script to find files of a directory that their ctime is newer than a ctime of files of an other directory.
That's being, here is my script:
Code:
****************************************************
#!/bin/bash
#defining my ctime
ctimesource=`stat /mydeirectory/ | grep Change: | awk '{print $2}'`
hctimesource=`stat /mydeirectory/ | grep Change: | awk '{print $3}' | cut -d"." -f1`
#defining the parameter to pass to find
myctime="'"$ctimesource" "$hctimesource"'"
echo $myctime
find /Bdirectory/ -newerct $myctime -type f
****************************************************
The thing is, if I run the command normally ( terminal): "find /Bdirectory/ -newerct $myctime -type f" after replacing the variable, it works like a charm.
Code:
find /Bdirectory/ -newerct '2014-01-30 16:12:20' -type f
It works
But when the command is used in a bash script, it doesn't work.
Here is the output of the script:
Code:
***************************************
'2014-01-30 16:12:20'
find: I cannot figure out how to interpret `\'2014-01-30 16:12:20\'' as a date or time
***************************************
I've tried single quotes, double quotes, replace the variable by `echo $myctime`, but still "find" couldn't correctly interpret the variable.
Do you have any idea? Appearantly the variable is not well formatted after being passed to the "find" command. Can you suggest something? Do you understand, why exactly it didn't work?
Thank you in advance,
PS:
Code:
bash -version
GNU bash, version 4.1.2(1)-release