0
I trying to copy a file to directory using awk filter based on time creation file
#!/bin/bash
dir=/home/resaputra23/pyexample/python2/*
des=/home/resaputra23/pyexample/backup/
file1= stat $dir | awk {'print $2'} | grep 2014
for i in $file1
do
cp $i $des || echo "unable to copy $i"
done
I get output
2014-12-02
2014-12-01
2014-12-28
But no copy file in $des
Some notes: to have a fast check of what is inside
– Hastur – 2015-04-22T18:14:22.537$file1
you can put before yourfor
anecho $file1 ; exit 0
, and remove when all will work. If you want to include the output of that pipe of commands in the variablefile1
you should writefile1=$(cmd1|cmd2...)
. Tostat
I'm afraid that it's possible to have the same doubt about the use of ls parsing opportunity. imagine the error you can incur if a filename tomorrow will have one space... You can try to protect somehow with"$1"
but is safer to usefind
.