Community discussions

MikroTik App
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Topic Author
Posts: 997
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Concatenate - how to properly escape double quotes?

Wed Aug 19, 2020 3:06 pm

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
 
excession
Frequent Visitor
Frequent Visitor
Posts: 95
Joined: Mon May 11, 2015 8:16 pm

Re: Concatenate - how to properly escape double quotes?

Mon Sep 14, 2020 5:54 pm

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?
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Topic Author
Posts: 997
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: Concatenate - how to properly escape double quotes?

Mon Sep 14, 2020 6:06 pm

Now that is brilliant!
Will try this first thing tomorrow morning.
Thanks a lot - the easiest things rarely are that obvious.

-Chris
 
pe1chl
Forum Guru
Forum Guru
Posts: 10183
Joined: Mon Jun 08, 2015 12:09 pm

Re: Concatenate - how to properly escape double quotes?

Mon Sep 14, 2020 6:43 pm

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.

Who is online

Users browsing this forum: Cloudtechiq [Bot], GoogleOther [Bot] and 13 guests