I am running the following commands in command line:
for DATAFILE in `find dir_name -type f -mtime +10 | egrep -v -e 'archive/'`
do
echo 'Data file name- ' "$DATAFILE"
echo 'Base name '
BASENAME=`basename "${DATAFILE}"`
DESTFILE="${BASENAME}"_`date +"%Y%m%d%H%M%S"`
echo "Dest file - "$DESTFILE
done
I get the following result for this:
Data file name- DIR_PATH_1/file_1.txt
Base name
Dest file - file_1.txt_20120719041239
Data file name- DIR_PATH_2/file_2.txt
Base name
Dest file - file_2.txt_20120719041239
When I put the same commands in a shell script and execute, I get the following result:
Data file name- DIR_PATH_1/file_1.txt
DIR_PATH_2/file_2.txt
Base name
Dest file - file_2.txt_20120719040956
I have checked the script for Control-M and other junk characters. Also, I don't have any extra steps in the shell script (no parameters and all).
Can someone point me in the right direction.
Thanks.
Update 1:
I made the following change to the loop:
Earlier:
for DATAFILE in `find ${ROOT_DIR} -type f -mtime +$DAYS_ARCH |
egrep -v -e 'archive/'`
Now:
find ${ROOT_DIR} -type f -mtime +$DAYS_ARCH |
egrep -v -e 'archive/' | while read DATAFILE
It seems to be working properly now. I am still testing to confirm this.
Update 2:
Changing from FOR to WHILE loop has fixed the issue. But still I am not able to understand why this is happening. Anyone?