Hello there -
I have three directories. I would like to compare directory1 with directory2, then take those changes/new files and copy them over to directory3. I was given the following code:
#!/bin/bash
dir2="d1"
dir1="d2"
dir3="d3"
for file in dir2/*; do
file_in_dir1=dir1/$(basename ${file})
if [ ! -e ${file_in_dir1} ]; then
# If the file in dir2 does not exist in dir1, copy
cp ${file} dir3
elif ! diff ${file} ${file_in_dir1}; then
# if the file in dir2 is different then the one in dir1, copy
cp ${file} dir3
fi
done
And I'm getting the following error: 7: Syntax error: word unexpected (expecting "do")
I don't have any experience in shell scripting. Can someone tell me what I need to do to get this script working...
Thanks!
Andrew