(solved) Little problem with "if" (ros 6.25)

Hello,
Can somebody open my eyes on where is my mistake, please. “If” doesn’t work for me in the following example. Where I’m trying to create short string from port name:

portname to portvlanID
ether1 to -e01
ether2 to -e02
..
ether10 to -e10
ether11 to -e11

:local portname "ether9"
:local portnumber "0"
:if (:pick $portname ( [:len $portname] - 2 ) = "1") \
   do={:set $portnumber "1$[:pick $portname ( [:len $portname] - 1)]"}\
   else={:set $portnumber "0$[:pick $portname ( [:len $portname] - 1)]"}
:local portvlanID "-$[:pick $portname 0 1]$portnumber"

(:pick $portname ( [:len $portname] - 2 ) = “1”) always returns “false”

bump…

Ok, in other words, how can i script (ether1, ether2,..,ether11,ether12,sfp1,sfp2) to (-e01,-e02,..,-e11,-e12,-s01,-s02)

To be use in the following script (would really like to calculate $portvlanID):

# ROS6 -- add new subnets (IP,NAT,Bridge,VLANport)
# no VLAN if port name is ""
# change from - to accordingly and locals

:local portname "ether9"
:local portvlanID "-e09"
:for i from=10 to=19 do={

/interface bridge
add name="bridge$i" protocol-mode=rstp
/ip pool
add name="pool$i" ranges="192.168.$i.50-192.168.$i.250"
/ip dhcp-server
add address-pool="pool$i" disabled=no interface="bridge$i" lease-time=4h name="dhcp$i"
/ip address
add address="192.168.$i.1/24" interface="bridge$i" network="192.168.$i.0"
/ip dhcp-server network
add address="192.168.$i.0/24" dns-server="8.8.8.8,8.8.4.4" gateway="192.168.$i.1"
/ip firewall address-list
add address="192.168.$i.0/24" list="subnets"
/ip firewall filter
add action=passthrough chain=forward dst-address="192.168.$i.0/24"
add chain=forward dst-address="192.168.$i.0/24" src-address="192.168.$i.0/24"
/ip firewall nat
add action=masquerade chain=srcnat src-address="192.168.$i.0/24" to-addresses="0.0.0.0"
/queue simple
add max-limit="5M/5M" name="queue$i" queue=default/default target="192.168.$i.0/24" disabled=yes
/tool graphing interface
add interface="bridge$i"

:if ($portname !="") do={
 /interface vlan
 add interface=$portname name="vlan$i$portvlanID" vlan-id="$i"
 /interface bridge port
 add bridge="bridge$i" interface="vlan$i$portvlanID"
 }
}

anybody?!

:frowning:
nobody can script, can we? help!

:local portname "ether9";
:local portvlanID;
:if ([:len $portname] = 6)  \
   do={:set portvlanID "-e0$[:pick $portname 5 6]";} 
   else={:set portvlanID "-e$[:pick $portname 5 7]";}

Thank you,
but what about sfp? I’m trying to catch last but one character and insert ‘0’ if interface number is less then 10, like so:
script (ether1, ether2,..,ether11,ether12,sfp1,sfp2) to (-e01,-e02,..,-e11,-e12,-s01,-s02)

I can’t figure out why (:pick $portname ( [:len $portname] - 2 ) = “1”) always returns “false”
Yuri

Thats because you forgot to use . try:

:if ([:pick $portname ( [:len $portname] - 2 )] = "1")

exactly, how didn’t i see this!