What Operating System and version?
What Shell?
How many files?
Was the script created on the unix server with a proper unix editor such as "vi" ? If not, what was used.
uname -a
echo $SHELL
find /dirA/dirB/ -name temp\*.log -print | wc -l
sed -n l scriptname
Just for interest the $ sign (only) at the end of the line when viewed with "sed" tells me that this is a normal unix text file.
The problem with the script is the backticks. Not required in this context and will cause the error you are seeing. It will try to execute each file in the directory list and fail on the first one because it is not in $PATH !
Removving the backticks is no solution, the result is the same (I had already played with this).
It is not first file on which it gives an error, it gives an error that the final file does not exist. It looks as though the system has difficulties with writing "nothing" to a file that does not exist.
I stand corrected. You get the issue I mentioned with `ls` (don't try it!).
Any space characters or non-printing characters in the filenames?
Is the directory automounted from another computer?
We can check that the filename globbing is working and check that the Shell generates the complete line.
echo cat /dirA/dirB/temp*.log
Btw. I hate open-ended lists on command lines. This construct more robust:
>/dirA/dirB/final.log
ls -1 /dirA/dirB/temp*.log 2>/dev/null | while read filename
do
cat "${filename}" >>/dirA/dirB/final.log ; REPLY=$?
if [ ${REPLY} -eq 0 ]
then
rm "${filename}"
fi
done