I have written an example code for reading the content of a file maitaining the end of line format using hack from the internet. I have called the shell file "pipeTesting" and the text file to display "textExample". "pipeTesting" works if I call the file as an argument of the shell script.
However, there are cases when files are retrieved via pipelines; if I provide the text to pipeTesting using a cat
command, there are no arguments at all since echo $@
does not print anything. To note that I had to use -p /dev/stdin
to create a case for pipeline usage and one for argument usage.
Is there a way to display the content of the file maitaining the end of the line in case of a pipeline?
thank you.
The code looks something like this:
#!/bin/bash
if [ -p /dev/stdin ]; then
echo $@
else
while read
do
echo $REPLY
done < $1
fi
exit 0
Its application is:
$ cat textExample.txt
Much I marvelled this ungainly fowl to hear discourse so plainly,
Though its answer little meaning- little relevancy bore;
For we cannot help agreeing that no living human being
Ever yet was blessed with seeing bird above his chamber door-
Bird or beast upon the sculptured bust above his chamber door,
With such name as "Nevermore."
$ pipeTester textExample.txt
Much I marvelled this ungainly fowl to hear discourse so plainly,
Though its answer little meaning- little relevancy bore;
For we cannot help agreeing that no living human being
Ever yet was blessed with seeing bird above his chamber door-
Bird or beast upon the sculptured bust above his chamber door,
With such name as "Nevermore."
$ cat textExample.txt | pipeTester
_