Bash Printf reversed the order of arguments

Viewed 57

It's a weird scenario I came across and I'm quite confused

$ printf "%s:%s\n" "$(date)" "$(python -V)"
Python 2.7.10
Thu 10 Oct 2019 19:05:11 EDT:

Whereas with other commands I get an expected result

$ printf "%s:%s\n" "$(date)" "$(hostname)"
Thu 10 Oct 2019 19:04:53 EDT:alvy.local
1 Answers

python -V prints to stderr. Use 2>&1 to redirect the output to stdout so it can be captured.

$ printf "%s:%s\n" "$(date)" "$(python -V 2>&1)"
Related