Script copy route table to another one route table

hi

This is script for copy route table to another one route table

::local Z 0;
:local checkIP 0;
:local ipAddress;
#name of source table
:local BGPIN 5G;
#name of destination table
:local T1 6G;
#name of gw of destination route table
:local gatewayT1 10.50.0.2;

#route ip address
/ip route
:foreach Z in=[find where routing-table=$BGPIN] do={
:local ipAddress [get $Z dst-address]

#Check present destination ip or not in target table
:local checkIP [/ip route print count-only where routing-table=$T1 dst-address=$ipAddress];
#if it is the default gateway don't add it

:if ($ipAddress=0.0.0.0/0) do={:set checkIP 2}

#If the IP is not in the destination table add it

:if ($checkIP = 0) do={
/ip route add dst-address=$ipAddress gateway=$gatewayT1 routing-table=$T1;}
}

And in case is already present on destination route table, but have another gateway?

Wrong for various reasons. Also superfluos ; , unconsistent variables name, etc.
Duplicated :: at start probably for copy-paste.
Also on the description missing that not only copy, but also change gateway.
{
:local routingTable “main”
:local dstTable “6G” ; # the table is supposed to already exist
:local newGateway 10.50.0.2
:local dstAddress 0.0.0.0

/ip route
:foreach item in=[find where routing-table=$routingTable] do={
    :local dstAddress [get $item dst-address]
    :if ($dstAddress!=0.0.0.0/0) do={
        :if ([:len [find where routing-table=$dstTable and dst-address=$dstAddress]] = 0) do={
            add routing-table=$dstTable dst-address=$dstAddress gateway=$newGateway
        }
    }
}

}