# How to solve space in linux path

**URL:** <https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946>\
**Category:** General\
**Created:** [23 December 2020 21:38 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946 "2020-12-23T21:38:41Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![coen17st](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coen17st/32/34027_2.png) [@coen17st](https://discourse.nodered.org/u/coen17st)\
**Post date:** [23 December 2020 21:38 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/1 "2020-12-23T21:38:42Z")

</div>

Hi, ik want to execute a rsync command but it doesn't work because there is a space in the path.

this is source path `/media/mediacenter/CANON XF2`

this is the command. i have put this line in a template node  
`rsync -vrhn "{{{payload}}}" /home/mediacenter/rib/out`

i get this error

`rsync: link_stat "/media/mediacenter/CANON XF2\#012" failed: No such file or directory (2) rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]`

suddenly the path becomes `/media/mediacenter/CANON XF2\#012`

when i put this command is the linux (ubuntu) terminal is works perfectly

```auto
rsync -vrhn "/media/mediacenter/CANON XF2" /home/mediacenter/rib/out

```

Node-RED flow

```auto
[{"id":"69a52fe4.a9407","type":"template","z":"9e40285b.9b7068","name":"rsync","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"rsync -vrhn \"{{{payload}}}\" /home/mediacenter/rib/out","output":"str","x":930,"y":800,"wires":[["18e03673.1e340a"]]},{"id":"18e03673.1e340a","type":"exec","z":"9e40285b.9b7068","command":"","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":1050,"y":800,"wires":[["5f15ab2.52de154"],["5f15ab2.52de154"],["5f15ab2.52de154"]]},{"id":"5f15ab2.52de154","type":"debug","z":"9e40285b.9b7068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":800,"wires":[]}]

```

how can i solve this issue?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [23 December 2020 21:43 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/2 "2020-12-23T21:43:40Z")

</div>

> [@coen17st](#):
>
> this is source path `payload` = `/media/mediacenter/CANON XF2`

Have you tried escaping the space?  
`/media/mediacenter/CANON\ XF2`

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [23 December 2020 21:46 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/3 "2020-12-23T21:46:11Z")

</div>

> [@coen17st](#):
>
> `"/media/mediacenter/CANON XF2"`

Add some extra quotes:  
`msg.payload = "\"/media/mediacenter/CANON XF2\""`

---

<div class="post-metadata">

**Author:** ![coen17st](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coen17st/32/34027_2.png) [@coen17st](https://discourse.nodered.org/u/coen17st)\
**Post date:** [23 December 2020 21:46 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/4 "2020-12-23T21:46:37Z")

</div>

I can't because the path is variable i have tried double quotes but is doesnt work

---

<div class="post-metadata">

**Author:** ![coen17st](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coen17st/32/34027_2.png) [@coen17st](https://discourse.nodered.org/u/coen17st)\
**Post date:** [23 December 2020 21:49 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/5 "2020-12-23T21:49:32Z")

</div>

I have tried this in a template node  
`rsync -vrhn "\"{{{payload}}}\"" /home/mediacenter/rib/out`

get this error

```auto
Command failed: rsync -vrhn "\"/media/mediacenter/CANON XF2
\"" /home/mediacenter/rib/out
rsync: change_dir "/home/mediacenter//"/media/mediacenter" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]

```

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [23 December 2020 21:52 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/7 "2020-12-23T21:52:55Z")

</div>

In the flow you posted it's not clear who or what is filling the {{payload}} variable.  
In this part you have to set the extra quotes, not in the rsync node.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 December 2020 21:54 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/8 "2020-12-23T21:54:02Z")

</div>

I don't think it is the space that is causing the problem. Feed the message coming in into a debug node and see us what it says. I suspect there is a new line on the end of the string (#012).

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [23 December 2020 22:03 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/9 "2020-12-23T22:03:12Z")

</div>

I think it's better to keep the rsync in the exec node and past the rest with a payload to the node.

```auto
[{"id":"7df77a3e.03d874","type":"exec","z":"55340790.3abc","command":"rsync","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":650,"y":300,"wires":[["75c5a255.f158ac"],["75c5a255.f158ac"],["75c5a255.f158ac"]]},{"id":"75c5a255.f158ac","type":"debug","z":"55340790.3abc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":300,"wires":[]},{"id":"fc716702.e8f6a8","type":"inject","z":"55340790.3abc","name":"","topic":"","payload":"-vrhn \"/media/mediacenter/CANON XF2\" /home/mediacenter/rib/out","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":450,"y":300,"wires":[["7df77a3e.03d874"]]}]

```

Or if you want for the first path a separate payload.

```auto
[{"id":"7df77a3e.03d874","type":"exec","z":"55340790.3abc","command":"rsync","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":750,"y":300,"wires":[["75c5a255.f158ac"],["75c5a255.f158ac"],["75c5a255.f158ac"]]},{"id":"75c5a255.f158ac","type":"debug","z":"55340790.3abc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":910,"y":300,"wires":[]},{"id":"fc716702.e8f6a8","type":"inject","z":"55340790.3abc","name":"","topic":"","payload":"/media/mediacenter/CANON XF2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":350,"y":300,"wires":[["3f37aa94.e8ad76"]]},{"id":"3f37aa94.e8ad76","type":"function","z":"55340790.3abc","name":"","func":"msg.payload = \"-vrhn \\\"\" + msg.payload + \"\\\" /home/mediacenter/rib/out\"\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":300,"wires":[["7df77a3e.03d874"]]}]

```

---

<div class="post-metadata">

**Author:** ![coen17st](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coen17st/32/34027_2.png) [@coen17st](https://discourse.nodered.org/u/coen17st)\
**Post date:** [23 December 2020 22:14 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/11 "2020-12-23T22:14:59Z")

</div>

> [@edje11](#):
>
> Or if you want for the first path a separate payload.
> 
> ```auto
> [{"id":"7df77a3e.03d874","type":"exec","z":"55340790.3abc","command":"rsync","addpay":true,"app
> 
> ```

Thank!! this works instead of a funtion node i using the template

```auto
[{"id":"7df77a3e.03d874","type":"exec","z":"9e40285b.9b7068","command":"rsync","addpay":true,"append":"","useSpawn":"false","timer":"60","oldrc":false,"name":"","x":810,"y":820,"wires":[["75c5a255.f158ac"],["75c5a255.f158ac"],["75c5a255.f158ac"]]},{"id":"75c5a255.f158ac","type":"debug","z":"9e40285b.9b7068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":950,"y":820,"wires":[]},{"id":"fc716702.e8f6a8","type":"inject","z":"9e40285b.9b7068","name":"","props":[{"p":"path","v":"/media/mediacenter/CANON XF2","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":490,"y":820,"wires":[["38196e14.7ec612"]]},{"id":"38196e14.7ec612","type":"template","z":"9e40285b.9b7068","name":"command complete","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"-vrhn \"{{{path}}}\" /home/mediacenter/rib/out","output":"str","x":650,"y":820,"wires":[["7df77a3e.03d874"]]}]

```

---

<div class="post-metadata">

**Author:** ![coen17st](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coen17st/32/34027_2.png) [@coen17st](https://discourse.nodered.org/u/coen17st)\
**Post date:** [23 December 2020 22:24 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/12 "2020-12-23T22:24:34Z")

</div>

Sorry to soon, apparently the problem wasn't the space, i still have the issue. could it be because the path is in an object and that's why it's not going well?

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/5283c35802d043d6b2e45b87b89588cb70767d8b.png)

could the enter arrow may be the problem and results in `#012`  
 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b371043ed7ebc7f39d80844812586b08baa7ff2d.png)

---

<div class="post-metadata">

**Author:** ![coen17st](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coen17st/32/34027_2.png) [@coen17st](https://discourse.nodered.org/u/coen17st)\
**Post date:** [23 December 2020 22:54 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/13 "2020-12-23T22:54:53Z")

</div>

Hi @Colin i think you are right. the question is how do I rid of that new line

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b371043ed7ebc7f39d80844812586b08baa7ff2d.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 December 2020 09:06 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/14 "2020-12-24T09:06:50Z")

</div>

> [@coen17st](#):
>
> how do I rid of that new line

The javascript `trim()` function will do that so in a function node you can do  
`msg.path = msg.path.trim()`  
if it is msg.path, I haven't studied the debug closely.  
However I would first look at where this comes from and remove the line feed at the earliest point possible, often it is simpler to remove it at the source, or prevent it getting there in the first place.  
I was fairly confident it was a new line that was the problem because 012 is octal 012 which is hex 0A which is the line feed character, and a filename should not have a line feed embedded in the name.

---

<div class="post-metadata">

**Author:** ![coen17st](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coen17st/32/34027_2.png) [@coen17st](https://discourse.nodered.org/u/coen17st)\
**Post date:** [29 December 2020 14:37 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/15 "2020-12-29T14:37:01Z")

</div>

Thanks @Colin i have solved the problem. I found also this solution to use in a function node.

```auto
msg.source = msg.path.replace(/\n/g,"");
return msg;

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 January 2021 14:37 UTC](https://discourse.nodered.org/t/how-to-solve-space-in-linux-path/37946/16 "2021-01-12T14:37:13Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
