Quantcast
Channel: User Kamil Maciorowski - Super User
Viewing all articles
Browse latest Browse all 668

Answer by Kamil Maciorowski for echo printf output in two lines for some expressions instead of one

$
0
0

jq --version prints to its stdout, so $(jq --version) manages to capture this output and everything works as you expect.

dig -v prints to its stderr. It probably should print to stdout, because it prints what you have requested and do expect (compare this answer); still it prints to stderr.

In echo "dig version: $(dig -v)", at first dig -v prints to its stderr, which usually (and certainly in your case) happens to be a terminal. Only when dig terminates, $() captures what dig has printed to its stdout: nothing. Then the command becomes echo "dig version: " and this gets executed.

You can redirect stderr to the open file description of stdout with 2>&1:

echo "dig version: $(dig -v 2>&1)"

Related:


Viewing all articles
Browse latest Browse all 668

Trending Articles