Cp not working in shell script but running perfectly from shell

Dear All,

I have script.

Dest=""
IFS=' 
'
for translation in $(echo $MY_MAP)
do
   t1=$(echo $translation | cut -d"=" -f1)
   t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1)
   
   if [ $u_testname = $t1 ]
   then
     	   Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2
      break;
   fi
done

if [ "x$Dest" = "x" ];
then
   Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$MAP_OTHER
fi

if [ ! -d $Dest ]
then
   mkdir -p $Dest
fi

echo "printing Filename:" $n_filezip_name "Destination :" $Dest/$l_filezip_name
echo "Current Working Directory:" 
echo cp -f $n_filezip_name $Dest/$l_filezip_name
pwd
cp -f $n_filezip_name $Dest/$l_filezip_name - This is not working

echo $?
  if [ $? -ne 0 ]
   then
      echo "$DATE [OCEDL ERROR] Not able to cp long_unix_name to $Dest"
  fi
IFS='
'
}

When i run this it produces
echo $? as 0
But if I run this from shell it does what it should do. Any Guess what is wrong I consider IFS is culprit but not able to debug it.

cp -f $n_filezip_name $Dest/$l_filezip_name

this is not working.

Any help or advise would be great help to me.

Thanks.

perhaps lack of quoting?

Try:

cp -f "${n_filezip_name}" "${Dest}/$1_filezip_name"

What is MY_MAP?

What is u_testname?

Why have you set IFS to a newline? If your goal is to read something line-by-line, it'd be better to use a while read loop.

You can simplify this: if [ "x$Dest" = "x" ]; into this: if [ -z "$Dest" ]

This section will never work right:

echo $?
  if [ $? -ne 0 ]
   then
      echo "$DATE [OCEDL ERROR] Not able to cp long_unix_name to $Dest"
  fi

...because echo sets the value of $? to zero after it runs.

I don't think IFS is the culprit; it doesn't seem you're using it anywhere.
n_filezip_name is not defined (at least in that code snippet).
And, after echo $? , the [ $? ... will test echo 's exit code, not cp 's.

I counted 10 variable that are not defined.

if [ ! -d $Dest ]
then
   mkdir -p $Dest
fi

This test will fail if the last name in the path of Dest resolves to another file type. I would test the exit code of mkdir. Something like this

mkdir -p "$Dest" || ( echo "EXITING SCRIPT"; exit )