How can I put a backslash before every space, preferably by using tr or sed commands?
Here is my script:
#!/bin/bash
line="hello bye"
echo $line | tr ' ' "\\\ "
This is supposed to replace spaces with a backslash followed by a space, but it's only replacing the spaces with a backslash and not backlash+space.
This is the output I get:
hello\bye
Expected output:
hello\ bye