0

I can understand the statements like.

  1. bzip2 --version >/tmp/list_right 2>/tmp/list_error
  2. bzip2 --version >/tmp/list 2>&1

But I don't understand the statement:

bzip2 --version 2>&1 < /dev/null | head -n1
2
  • bzip2 --version outputs info to stderr but pipe (|) transfer stdout only. So in the case to be able format info (prints just 1st line) the stderr of bzip2 --version is redirected to stdout. Is there any reason to input /dev/null I have no idea.
    – Costas
    Mar 1 '15 at 12:43
  • this question is not constructive. Mar 1 '15 at 13:04
1

2>&1 duplicates standard output as standard error. </dev/null redirects standard input to the null character special device, eof is encountered immediately when reading. |head -n1 pipes standard output to the command, thus the first line is printed, and lines after the first are discarded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.