I have to do an exercise: there is a file which contains this text
dirA dirB
dirX dirY
dirA dirD
Each line has two directories, the script must check for each line if any file of the first directory is contained in the second directory. Here is the script:
if [ $# -ne 2 ];then
echo "Error! Insufficient parameters"
exit 1
fi
if [ ! -f $1 ];then
echo "$1 is not a file"
exit 2
fi
if [ -f $2 ];then
echo "$2 already exists"
exit 3
fi
file=$(cat $1)
file_output=$(touch $2)
count=0
dir_a=''
dir_b=''
for i in $file ; do
if [ $count -eq 0 ];then
dir_a=$i
let count=$count+1
continue
fi
if [ $count -eq 1 ];then
dir_b=$i
let count=0
for f in $(ls $dir_a) ; do
if [ -f $dir_b/$f ];then
echo "found"
fi
done
fi
done
The problem is that it doesn’t check the last couple, in the case of the example above it won’t check the couple “dirA dirD”.
Any ideas for this strange behavior?
….. What?