@rangarasan
Danger:
The main issue is that the script will issue "rm -rf" on any unique directory which your "ls" finds. You should not have the "-r" parameter in this script.
Even if it is a file, the script deletes the files from the wrong directory.
Part of this is pandeesh's really vague specification of the third parameter. I actually believe that he meant to "move" not "remove" the files to the third directory.
Design:
Quote:
for file1 in `ls $dir1`
for file2 in `ls $dir2`
Any names containing space characters will get split into partial names.
itkamaraj's code does not have this problem, but it does have other problems.
The script repeatedly searches $dir2 for matching names one-by-one (inefficient and avoidable).
There is no check that what is output by "ls" is actually a file. It could be a directory in which case we have a disaster.
Syntax:
Quote:
`\rm -rf "$base/$file1"`;
This is unix not Oracle. There is never a reason to end a line in Bourne-type script with a semi-colon. You have many lines like that.
Never use backticks in a standalone line. It will not always behave.
Presumably the "\rm" is to avoid an alias for "rm" on your system.
That single line contains more errors than I have seen in a single line for some time.
Forgot to mention that pandeesh should probably have been looking at the unix "dircmp" command.