I'm new to bash and would like your help; couldn't find an answer for this case. I'm trying to check if the files in one directory exist in another directory
Let's say I have the path /home/public/folder/ (here I have several files) and I want to check if the files exist in /home/private/folder2
I tried that
for file in $firstPath/*
do
if [ -f $file ]; then
(ask if to over write etc.. rest of the code)
And also
for file in $firstPath/*
do
if [ -f $file/$secondPath ]; then
(ask if to over write etc.. rest of the code)
Both don't work; it seems that in the first case, it compares the files in the first path (so it always ask me if I want to overwrite although it doesn't exist in the second path) And in the second case, it doesn't go inside the if statement. How could I fix that?
$fileand$secondPathbackwards. Tryif [ -f "${secondPath}/$(basename ${file}) ]basenameto extract the name portion of the path from$file. So something likeif [ -f $secondPath/$(basename "$file") ]; then.