What you're observing indicates that nginx -V writes its output to the standard error stream (aka stderr - on file descriptor 2) rather than the standard output stream (aka stdout - file descriptor 1). Only stdout gets passed through the pipe | so your tr command doesn't receive it.
The 2>&1 syntax tells the shell to redirect stderr to stdout so that it then gets piped to tr. FYI the placement you have used is syntactically legal but unconventional - most often that kind of redirection would be written as
nginx -V 2>&1 | tr -- - '\n'
BTW the pipe | is really redirecting the output of the first command rather than the input of the second, which is coming from the standard input stream (stdin - file descriptor 0) as usual.
What you're observing indicates that
nginx -V
writes its output to the standard error stream (akastderr
- on file descriptor2
) rather than the standard output stream (akastdout
- file descriptor1
). Onlystdout
gets passed through the pipe|
so yourtr
command doesn't receive it.The
2>&1
syntax tells the shell to redirectstderr
tostdout
so that it then gets piped totr
. FYI the placement you have used is syntactically legal but unconventional - most often that kind of redirection would be written asBTW the pipe
|
is really redirecting the output of the first command rather than the input of the second, which is coming from the standard input stream (stdin
- file descriptor0
) as usual.