While read line in shell

Guys,

I have a requirement like below
my cfg file(sam.cfg) has

path=/u/sample/test/
path=/u/sample1/test1/
path=/u/sample2/test2/
days=10
file=*.log

My script is below,

#!/bin/sh
 
./u/sample/sam.cfg
 
while read line
do
find $path -name "$file" -mtime +$days -exec ls -la {} \; 2> /dev/null > sam.log
done < sam.cfg

if i execute this, this is only finding the files under path /u/sample2/test2/ . (taking the last path mentioned in cfg).
Its not finding the files from the ( path=/u/sample/test/ ) and ( path=/u/sample1/test1/ )
Could you please anyone help me on this?

Appreciate your help!!!

Thanks,

You're overwriting the variable 'path' and setting it with a new value when you read in the cfg file. Instead try something like this:

path="/u/sample/test/ /u/sample1/test1/ /u/sample2/test2/"
days=10
file=*.log
./u/sample/sam.cfg
for p in $path ; do 
find $p -name "$file" -mtime +$days -exec ls -la {} \; 2> /dev/null > sam.log
done

Maybe you can try this line that way :

. ./u/sample/sam.cfg

or

. <absolute path>/sam.cfg