I'm not clear if a loop is needed for any reason, nor if by "touching" the file you want to change the date stamp in the name fo the file or just the atime, but this seems to be better handled by the find command, like "find from /app name *2008* | exec touch the file" .
But i was thinking in doing it with for loop so that i could have better chance to check if any of files in these directories misses out the touch command.
With touch i just wanted to the file to reflect the current sysdate and time.
i was thinking something like this
base_dir=/app/data
var1=/eng
var2=/med
var3=/bsc
for <list of direcotries> in <parentdir>
do
for i in *.20081230* // searchin each of directories /data ,/med, /bsc for files to touch
do
touch *
if [ -ne 0 ]
then
echo "failed to touch `$1` "
fi
done
What do you expect a failure of the touch command to tell you?
Don't you mean:
for <directory> in <list of directories in parentdir>
Why touch everything on every iteration of the loop?
If you do that, you will have no idea which file failed to be touched.
Syntax error. That should be:
if [ $? -ne 0 ]
That will try to execute the contents of $1 as a shell command. You mean:
echo "failed to touch '$1' "
for dir in "$base_dir/$var1" "$base_dir/$var2" "$base_dir/$var3"
do
(
cd "$dir" || continue
for i in *.20081230*
do
touch "$i"
if [ $? -ne 0 ]
then
echo "failed to touch '$1' "
fi
done
)
done