I have a shell script that takes input from another shell script. The stream gets piped in on stdin.
I need to capture all the bytes of the stdin stream to a single variable in the shell script. Then, perform some operations on it, and send it back out over stdout.
The problem I have is that sometimes there is a trailing newline character in the input file, but sometimes there is not. If there is not, then I do not want to add one. If there is a trailing newline, however, I want to preserve that.
The problem is that no matter what I try, the system either always outputs WITHOUT a trailing newline (as in the case of
printf) or it always outputs WITH a newline (as in the case of
Please tell me what is the name of a process (not
printf) that simply takes a variable and streams it out, verbatim, byte for byte, over stdout. I have tried all possible options for
printf and none of them works to preserve trailing newlines.