Revised version of question:
cat - | tr "a-z" "A-Z" | tr "A-Z" "a-z"
does not give any output when I run it on my bash shell prompt. I have to press Ctrl-D to get the o/p.
o/p
$ cat - | tr "a-z" "A-Z" | tr "A-Z" "a-z"
this is a test
However this works just fine and I get the output without using Ctrl-D..Why ?
cat - | tr "a-z" "A-Z"
o/p
$ cat - | tr "a-z" "A-Z"
this is a test
THIS IS A TEST
Original version of question:
cat "$@" | tr "a-z" "A-Z" | tr "A-Z" "a-z"
hangs when I run it on my bash shell prompt. Why is that?
My $@ is empty.
However this works like this
cat "$@" | tr "a-z" "A-Z"
What you’re seeing is due to buffering. In
(no quotes needed) you may not get the output immediately after you hit
ENTER, because the middle or third
trmay have buffered the datainternally. At some point, they will flush their buffers and you’ll get
the full, correct output. Hitting Ctrl-D closes the pipe and forces a flush.
This is a fairly typical phenomenon when connecting several commands in one
pipe.
By the way, in this case (but not when using “$@”), the
cat -is superfluous.