I would like to check the file check sums between 2 directories.
I have written the following script to do so:
#!/bin/bash
echo Checking File Copy
SRC_DIR=/home/user/src
echo Source Directory: $SRC_DIR
TGT_DIR=/media/user/tgt
echo Target Directory: $TGT_DIR
cd $SRC_DIR
for file_name in *.txt
do
echo $file_name
tgt_file=${file_name// /\\ }
sum $TGT_DIR/$tgt_file
sum $file_name
done
The script works fine until it encounters a file with space in the name at which point I get an error.
I tried to solve it by "escaping" the file name like so:
tgt_file=${file_name// /\\ }
Unfortunately that causes an error when reading the file names.
I have searched but have not found an answer that seems to work. Any suggestions would be very welcome. Thanks.