I want to get proper output from FOR loop inside WHILE. When i'm using command like this all is OK:
for i in `find ./ -name "*.processed" -mtime +0`; do echo "$i is COOL"; done;
Output:
1.processed is COOL
2.processed is COOL ...
But, when i'm using this into bash/shell script, find put a list of all files with proper mask into variable (not one by one). Note, redirect "echo $i is COOL" to "wc -l" returns number of all files, damn. See following: Entries of confif file like:
/export/home/.../ProcessedDumps;*.processed
All paths are full paths.
#!/bin/bash
CONF_FILE=$1
DAYS_OLD=0
counter=0
IFS=";"
if [ "$1" = "-h" -o "$1" = "-help" -o "$#" -ne "1" ]; then
echo "Just archive your files easy!"
echo "Usage: `basename $0` /path_to_conf/config.cfg" && echo "Exit!"
exit 1
fi
echo "#########################"
date '+Date: %Y.%m.%d %T'
echo
while read LOG_DIR MASK
do
cd $LOG_DIR
echo "Dir changed to `pwd`"
echo "Searching with mask \"$MASK\""
for i in `find . -name "$MASK"`
do
echo "$i is COOL"
echo "test"
done
done < $CONF_FILE
echo
echo "Total archived files: $counter"
echo
date '+Date: %Y.%m.%d %T'
Output:
1.processed
2.processed
...
n.processed is COOL
test
Is bash provides nested loops with different kinds (inner FOR, outer WHILE). Have any ideas?
findisn't being split so you're onlyforing over one thing. IsIFSset?find . -name $MASK?cddo you give absolute path or relative?find ./ -name "*.processed -mtime +0"have beenfind ./ -name "*.processed" -mtime +0? (quotes only around file name...)