0

With bash, how to get 1 Line from xxhsum --version ?

Ubuntu 20.04.4 LTS (Focal Fossa)

Why unexpected bash results with
pipe | head and
pipe | awk ?

Examples below work as expected:

md5sum --version

md5sum (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later https://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Ulrich Drepper, Scott Miller, and David Madore.

md5sum --version | head -n1
md5sum (GNU coreutils) 8.30

md5sum --version | head -n 1
md5sum (GNU coreutils) 8.30

md5sum --version | awk 'NR==1'
md5sum (GNU coreutils) 8.30

But there is a faster hasher
xxhsum
i am testing it, also called
xxhash

xxhsum --version
xxhsum 0.8.1 by Yann Collet
compiled as 64-bit x86_64 autoVec little endian with GCC 9.3.0

All the above is as expected.
But unexpected results with:

xxhsum --version | head -n1
xxhsum 0.8.1 by Yann Collet
compiled as 64-bit x86_64 autoVec little endian with GCC 9.3.0

xxhsum --version | head -n 1
xxhsum 0.8.1 by Yann Collet
compiled as 64-bit x86_64 autoVec little endian with GCC 9.3.0

xxhsum --version | awk 'NR==1'
xxhsum 0.8.1 by Yann Collet
compiled as 64-bit x86_64 autoVec little endian with GCC 9.3.0

unexpected results because
2 Lines are printed to screen, not 1 Line.

Regarding xxhsum ...
How come 2 Lines are printed to screen?

How to get 1 Line printed from
xxhsum --version ?

--

joseph22
  • 157
  • 1
  • 9
  • If `xxhsum --version 2>&1 | head -n1` does not solve the problem then please leave me a comment and I will reopen the question. – Kamil Maciorowski Jun 07 '22 at 15:31
  • Somewhat related: [Determine if output is stdout or stderr](https://superuser.com/q/453598/432690). – Kamil Maciorowski Jun 07 '22 at 15:34
  • Kamil' answer: ```xxhsum --version 2>&1 | head -n1``` gives desired 1 Line output ```xxhsum 0.8.1 by Yann Collet``` and the provided web page -- how to Determine if output is stdout or stderr with ```{ { xxhsum --version; } 2>&3 | sed 's/^/STDOUT: /'; } 3>&1 1>&2 | sed 's/^/STDERR: /'``` gives an answer stating STDERR meaning: ```STDERR: xxhsum 0.8.1 by Yann Collet``` ```STDERR: compiled as 64-bit x86_64 autoVec little endian with GCC 9.3.0``` . – joseph22 Jun 07 '22 at 16:42

0 Answers0