# Define a multiline variable using catenate and dots without spaces

**URL:** <https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699>\
**Category:** Robot Framework\
**Created:** [14 August 2024 09:30 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699 "2024-08-14T09:30:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [14 August 2024 09:30 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/1 "2024-08-14T09:30:52Z")

</div>

Hi,

i’m looking for a way to use variable and catenate it because my variable is a “sed” linux command which is quite long and i want to have it user-friendly readable.  
My “sed” command does a modification in a file by finding a string and then adding 4 new lines.

As of now everything is working BUT i face a trailing “space” in my file because of the […] of catenate which add this space.

So my command is this:

```
${command}= Catenate
... sed -i '/Environment="XDG_RUNTIME_DIR=\\/run\\/user\\/1302"/a\Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\\n
... Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"\\nEnvironment="QT_QPA_EGLFS_KMS_CONFIG=\/home\/ui\/display.json"\\n
... Environment="QT_QPA_EGLFS_HIDECURSOR=0"' /lib/systemd/system/myfile.service

```

Now i use “Execute Command” from SSHLibrary to run this on my remote device (where i’m connected to using open connection and login with ssh key from SSHLibrary.

Now if i look on my “myfile.service” i see this:

```
Environment="XDG_RUNTIME_DIR=/run/user/1302"
Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"
 Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"
Environment="QT_QPA_EGLFS_KMS_CONFIG=/home/ui/display.json"
 Environment="QT_QPA_EGLFS_HIDECURSOR=0"

```

So the sed worked fine. It found the line and using “/a” (for append) it appended the line.  
Now my sed do a \n to create a new line to add it which works - BUT because of the […] dots on catenate there is a trailing “space” at the beginning of line 3 and line 5 which are present in the file.

So the problem is that after this line

```
/a\Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\\n

```

we see the […] from catenate and this will add the space in next line that’s why the next line starts with a space in the file which you can see

And the same happens after this line:  
Environment=“QT\_QPA\_EGLFS\_KMS\_CONFIG=/home/ui/display.json”\n

here we have again the […] which results in a trailing space in the file

What i can also do is to put the whole sed command as a one liner directly to Execute Command like this:

```
Execute Command sed -i '/Environment="XDG_RUNTIME_DIR=\\/run\\/user\\/1302"/a\Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\\nEnvironment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"\\nEnvironment="QT_QPA_EGLFS_KMS_CONFIG=\/home\/ui\/display.json"\\nEnvironment="QT_QPA_EGLFS_HIDECURSOR=0"' /lib/systemd/system/myfile.service

```

This is also working fine WITHOUT spaces - but in my vscode this line is very long and not handy to read for others.

So any ideas?

For now i plan to just define 3 string variables and just use “Evaluate”

Br,  
Camil

---

<div class="post-metadata">

**Author:** ![FrancisG](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/francisg/32/4247_2.png) [@FrancisG](https://forum.robotframework.org/u/FrancisG)\
**Post date:** [14 August 2024 10:10 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/2 "2024-08-14T10:10:58Z")

</div>

Not sure if it answers your question, but you could try using the [SEPARATOR=[sep] feature](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#dividing-data-to-several-rows) to define how to join a string defined on multiple lines.

If you are using RF 7 this is compatible with the new VAR syntax (see [here](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-variables)), but I would assume it works on older frameworks _Set Test Variable_ & co.

Actually [_Catenate_ keyword also has a SEPARATOR argument](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Catenate).

---

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [14 August 2024 10:56 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/3 "2024-08-14T10:56:00Z")

</div>

Hi,

i tried with the SEPERATOR=\n - but this doesn’t helped me.

Maybe what i should mention is that i have defined my ${command} variable inside my Keyword - NOT in the _ **Variables** _ section.

So i moved my command to the _ **Variables** _ section and created it like this:

```
${sed_command}= 
... sed -i '/Environment="XDG_RUNTIME_DIR=\\/run\\/user\\/1302"/a\Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\\n
... Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"\\nEnvironment="QT_QPA_EGLFS_KMS_CONFIG=\/home\/ui\/display.json"\\n
... Environment="QT_QPA_EGLFS_HIDECURSOR=0"' /lib/systemd/system/myfile.service

```

Then i called this in my keyword

```
Execute Command ${sed_command}

```

But the result was the same. For the […] a space will be added as trailing space to the line in my file.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [14 August 2024 12:06 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/4 "2024-08-14T12:06:50Z")

</div>

> [@camilb](#):
>
> ```python
> ${command}= Catenate
> ... sed -i '/Environment="XDG_RUNTIME_DIR=\\/run\\/user\\/1302"/a\Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\\n
> ... Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"\\nEnvironment="QT_QPA_EGLFS_KMS_CONFIG=\/home\/ui\/display.json"\\n
> ... Environment="QT_QPA_EGLFS_HIDECURSOR=0"' /lib/systemd/system/myfile.service
> 
> ```

If you look at the documentation you can see that passing an empty separator does what you need.

Here is a screenshot of my favorite IDE 😉

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/8/89ec638bd0f82c87e152fab965f19c2e22e6ab3e.png)

The same is applicable to multi-line variables in the **Variables** section.  
And now the new **VAR** command marker also supports SEPARATOR.

---

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [14 August 2024 12:23 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/5 "2024-08-14T12:23:36Z")

</div>

Hi,

i tried it with SEPERATOR=  
but no luck. Also if i define it in the \*\*\* Variables \*\*\* section.

From the log i see this:

```
INFO Executing command 'SEPERATOR= sed -i '/Environment="XDG_RUNTIME_DIR=\/run\/user\/1302"/aEnvironment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\n Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"\nEnvironment="QT_QPA_EGLFS_KMS_CONFIG=/home/ui/display.json"\n Environment="QT_QPA_EGLFS_HIDECURSOR=0"' /lib/systemd/system/myfile.service'.

```

If you look closer you see a space after “…500”\n Environment…"  
And the second space you see after “…display.json”\n Environment"

This space is added TO the sed command and therefore sed will put it to my file  
It looks like this

![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/3/3bc06f6f624d1d2e73da054bb5ab10a8f2ea4d31.png)

And now you see that 2 lines starts with a beginning space.

So for some reason the dots […] are turned into space and will be added to the “sed” command which ofc is not what i want.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [14 August 2024 12:37 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/6 "2024-08-14T12:37:47Z")

</div>

Here is my complete example, for Robot Framework version 7.0.1:

```python
***Variables***
${table_command} sed -i '/Environment="XDG_RUNTIME_DIR=\\/run\\/user\\/1302"/a\Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\\n
... Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"\\nEnvironment="QT_QPA_EGLFS_KMS_CONFIG=\/home\/ui\/display.json"\\n
... Environment="QT_QPA_EGLFS_HIDECURSOR=0"' /lib/systemd/system/myfile.service
... separator=

***Test Cases***
Using Step Variable
    ${command}= Catenate SEPARATOR=
    ... sed -i '/Environment="XDG_RUNTIME_DIR=\\/run\\/user\\/1302"/a\Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=500"\\n
    ... Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=400"\\nEnvironment="QT_QPA_EGLFS_KMS_CONFIG=\/home\/ui\/display.json"\\n
    ... Environment="QT_QPA_EGLFS_HIDECURSOR=0"' /lib/systemd/system/myfile.service
    Log Variable is ${command} html=True

Using Table Variable
    Log Variable is ${table_command} html=True

```

---

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [14 August 2024 13:12 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/7 "2024-08-14T13:12:09Z")

</div>

What is your html log showing here

> [@camilb](#):
>
> `_WIDTH=500"\n Environment=`

and here

> [@camilb](#):
>
> `/display.json"\n Environment=`

Do you see a space between \n and Environment?

because for me i see a space - see the red mark

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/c/c4a1ac759a889406de9d932fbf41a9f267fa04c7.png)

im using  
robot --version

Robot Framework 7.0 (Python 3.10.12 on linux)

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [14 August 2024 13:20 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/8 "2024-08-14T13:20:04Z")

</div>

Hi,

In your variable you wrote “SEPERATOR” with an e, so it’s not recognized and added to the variable.  
You have to use SEPARATOR=

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [14 August 2024 13:22 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/9 "2024-08-14T13:22:34Z")

</div>

The command you are using is for SSHLibrary, not variable definition.  
Your command is defining a Linux variable, `SEPARATOR` and then running `sed`.  
Did you tried my code?  
See the user guide for the **Variables** section for Robot Framework versions older than 7.0.1.

---

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [14 August 2024 13:22 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/10 "2024-08-14T13:22:51Z")

</div>

OMG !!!

you are right - wrong spelling.  
Now using SEPARATOR=  
it is working and the file was modified with sed as expected.

![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/d/d087ee8d105a30baf1a7d1ea5111bdf97130357c.png)

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [14 August 2024 13:27 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/11 "2024-08-14T13:27:03Z")

</div>

Nice 😉

Also even better, since v7.0 version and VAR implementation, I barely use Catenate keyword with SEPARATOR when no separator is needed.  
You can define your variables, then create your final command one by adding them:

```
VAR ${VAR1} CONTENT1
VAR ${VAR2} CONTENT2
VAR ${VAR3} CONTENT3
VAR ${CMD} ${VAR1}${VAR2}${VAR3}

```

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [14 August 2024 13:29 UTC](https://forum.robotframework.org/t/define-a-multiline-variable-using-catenate-and-dots-without-spaces/7699/12 "2024-08-14T13:29:09Z")

</div>

Thx for the hint.  
Yes it’s something i can use as well.

Br,  
Camil
