I learned that in order to capture the output of a Unix command one should use something like
RESULT=$(command in question)
I want to capture the version of fsarchiver to the variable RESULT because the former option -z of fsarchiver has been deprecated. One should use -Z instead for version 0.8.4 (the one used under Ubuntu 18.04 LTS). In order to apply the right compression level in my script, it has to distinguish the current version of fsarchiver.
So I tried this:
$ RESULT=$(fsarchiver --version)
fsarchiver 0.6.22 (2016-02-13)
$ echo "${RESULT}"
$
so this one just returns an empty line. However I can determine the version of ls this way so I am sure to not have completely misunderstood capturing the output of a command to a variable in a bash script:
$ RESULT=$(ls --version)
$ echo "${RESULT}"
ls (GNU coreutils) 8.25
Copyright © 2016 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder höher <http://gnu.org/licenses/gpl.html>
Dies ist freie Software: Sie können sie ändern und weitergeben.
Es gibt keinerlei Garantien, soweit wie es das Gesetz erlaubt.
Geschrieben von Richard M. Stallman und David MacKenzie.
$
Why do ls and fsarchiver behave differently with respect to capturing their results when asking for their versions?
annotate-outputto see where output is being written. – Stephen Kitt Jan 13 '19 at 16:44