I have a simple bash script on RHEL that works fine when there is one file but when it finds multiple files of same condition I get too many args error.
for i in *
do
if [ ! -f "$i" ];then
echo "no files to move"
exit 0
fi
if [ "$i" = *02.DAT ]; then
mv $i $CD/somefolder/
fi
Single are an old-fashioned syntax which is kept for compatibility. [] does all the same things and more. == is an extended syntax which allows glob-matching like you do.
In that case, the or `||' is not necessary since `mv' is going to show in stderr the failure.
Also, there's the possibility that *02.dat does not give any proper result to the for loop.