Please use double quotes to avoiding replaces of the `\r to space when using bash evaluation or assignments, or strip operations::
echo "$l" | hexdump -C
00000000 68 6f 6c 61 0a 68 61 6c 6c 6f 0a 68 65 6c 6c 6f |hola.hallo.hello|
00000010 0a
سؤال
I have one file a with content:
hola
hallo
hello
I wrote this script to read its content:
#!/bin/bash
l=`cat a`
echo $l | hexdump -C #this line is only for debugging
#another program will use the content of $l after I write $l to a fifo
echo $l > my_fifo &
#program reads my_fifo
......
its content was changed after the first echo:
00000000 68 6f 6c 61 20 68 61 6c 6c 6f 20 68 65 6c 6c 6f |hola hallo hello|
00000010 0a |.|
actually it should be:
$ cat a | hexdump -C
00000000 68 6f 6c 61 0a 68 61 6c 6c 6f 0a 68 65 6c 6c 6f |hola.hallo.hello|
00000010 0a |.|
I dont think using "sed 's/ /\n/g'" to replace all spaces is a good idea, because my input-file is actually not so simple. how to keep it unchanged after echo?