You’re incorrectly using “string interpolation” is your main issue…
:local fileup "$[$identitydate].txt-dynamicdata"
with $identitydate being a string variable, so should be following:
:local fileup "$($identitydate).txt-dynamicdata"
or
:local fileup "$identitydate.txt-dynamicdata"
should work.
… and mistake is repeated throughout.
Essentially DO NOT USE square brackets to access a variable! Square bracket run commands/functions and what returned is put into the string. String and numbers in variable are not functions/commands, so they don’t “return” anything – only store. So all the place you’re putting a varable into a string use “my string is $mystr”.
Perhaps an example help:
{
:local myvar Mikrotik
:local “my-var-kabab” Mikrotik
:put “a command’s return value using brackets: $[/system identity get name]”
:put " vs"
:put “using a simple variable in string is just a dollar sign and var name, so: $myvar”
:put " BUT for more complex names or part of array or variables ‘touching’, you need use a ‘grouping’ $(…), here: $($“my-var-kabab”)"
:put “* as shown, use CAN use unescaped quotes INSIDE the grouping syntax $(parenthesis) "
:put " note above use the dollar sign needs to be escaped to be printed $”
:put " along with backsplash that escape the dollar too, so \$ if we wanted the backsplash in output"
:global myarray {“mykey”:“ex”; “mystr”=“sometext”}
:put “now if the variable your including in string is an ‘array’ type… it also uses the ‘dollar grouping’ with parenthesis syntax”
:put “so to get the mystr value inside myarray that just $($myarray->“mystr”)”
:put “* IMPORARTANTLY array types SHOULD NOT be used DIRECTLY in a string”
:put " while $myarray in string is allowed, and may work, just complex logic gets involved always using ‘$[:tostr $myarray]’ avoid this"
:put " so to :put an ENTIRE array, you start with the :tostr COMMAND, like: $[:tostr $myarray] "
:put " note the :tostr is a command that RETURNS, so why it uses square brackets"
}
a command’s return value using brackets: bigdude
vs
using a simple variable in string is just a dollar sign and var name, so: Mikrotik
BUT for more complex names or part of array or variables ‘touching’, you need use a ‘grouping’ $(…), here: Mikrotik
- as shown, use CAN use unescaped quotes INSIDE the grouping syntax $(parenthesis)
note above use the dollar sign needs to be escaped to be printed $
along with backsplash that escape the dollar too, so $ if we wanted the backsplash in output
now if the variable your including in string is an ‘array’ type… it also uses the ‘dollar grouping’ with parenthesis syntax
so to get the mystr value inside myarray that just sometext
- IMPORARTANTLY array types SHOULD NOT be used DIRECTLY in a string
while $myarray in string is allowed, and may work, just complex logic gets involved always using ‘$[:tostr ex]’ avoid this
so to :put an ENTIRE array, you start with the :tostr COMMAND, like: ex;mystr=sometext
note the :tostr is a command that RETURNS, so why it uses square brackets