Page 1 of 1

Concatenate - how to properly escape double quotes?

Posted: Wed Aug 19, 2020 3:06 pm
by cdiedrich
Good afternoon all,

I'm trying to create a custom probe with passing device_property("FirstAddress") into a ros_command by concatenating the string. I'm struggling to correctly escape double quotes into the concatenated result.

Escaping with a leading \ I get a "parse error" as well as with putting the double quotes into a set of single quotes ('"') with three double quotes in a row (""") It seems to stop right after the first of these sets.
Haven't found anything useful in the manual and forum yet...

Assuming "FirstAddress" is 192.168.250.7 the command I like to achive would be this:
:put [$myfunction 192.168.250.7]
And this is my concatenate approach so far:
ros_command(concatenate('"':put [$myfunction ", device_property("FirstAddress"),"]'"'))
Any help would be highly appreciated.
Thanks!

-Chris

Re: Concatenate - how to properly escape double quotes?

Posted: Mon Sep 14, 2020 5:54 pm
by excession
Just throwing out this idea / haven't thought about it too hard / almost certainly won't work / wasting my time and yours...
Could you try calling the "FirstAddress" variable in a new dude function then use that dude function in it's place in your concatenate line?

Re: Concatenate - how to properly escape double quotes?

Posted: Mon Sep 14, 2020 6:06 pm
by cdiedrich
Now that is brilliant!
Will try this first thing tomorrow morning.
Thanks a lot - the easiest things rarely are that obvious.

-Chris

Re: Concatenate - how to properly escape double quotes?

Posted: Mon Sep 14, 2020 6:43 pm
by pe1chl
My experience with RouterOS scripting is that you cannot make expressions more and more complex and expect them to behave like most programming languages would.
I.e. you could assign some expression to a variable, you can pass some constant or variable to a function as a parameter, but that does not necessarily mean you can pass a complex expression as a parameter to a function.
It is not clear to me where the limits are. Try to put the concatenate result in a variable first and then pass that variable to the function.