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