Get last entry from RoS

Hello,
I can list for example entries from firewall:

[hape@router1] /ip firewall nat> print 
Flags: X - disabled, I - invalid, D - dynamic 
 0    ;;; NAT 1
      chain=srcnat action=masquerade src-address-list=VPN_POOL dst-address-list=PEERING_1 log=no log-prefix="" 

 1    ;;; NAT 2
      chain=srcnat action=masquerade src-address-list=VPN_POOL dst-address-list=PEERING_1 log=no log-prefix="" 

 2    ;;; NAT 2
      chain=srcnat action=masquerade src-address-list=VPN_POOL dst-address-list=PEERING_1 log=no log-prefix=""

But how to get/print last value with id 2?

:foreach ID in=[/ip fire nat find comment="NAT 2"] do={:set $lastLine $ID}; print where .id=$lastLine;

Hi @msatter, @HaPe/OP, anybody:

I’ve created this script and installed it under /system/script under the name myTest1,
and I do run it with “run myTest1”. But it prints only the first of the :put’s (ie. the interfaces, but not their IPs), whereas
if I execute the two foreach blocks individually in the shell prompt then both do print correct results (here ether2 and ether24 do have IPs).

Ie. I think there is a bug in the script executor (what a name! :slight_smile:), or its parser.
Tested in 7.0beta5 on CRS326.

[admin2@MikroTik] /system/script> print 
Flags: I - invalid 
 0   name="myTest1" owner="admin2" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon dont-require-permissions=no last-started=may/09/2020 10:33:54 run-count=4 
     source=
       # myTest1
       
       :foreach i in=[/interface find type=ether ] do={
         :put ("+-- " . [/interface get $i name]);
         :foreach j in=[/ip address find interface=$i] do={
           :put ("|  `--" . [/ip address get $j address]);
         }
       }