Ah! Now it makes sense to me why you ask this.
You want to store the output of rsync in a variable so you can store the output in a log later. But you also want to see the output as it runs, right?
Though "set -x" would more or less do it for you, I think it is not the best solution. In fact, storing the output in a variable and the later echo it to a file is not a very good idea IMO. If many files are backed up the variable may consume quite a lot of memory (the --progress option will make rsync write two lines for every file backed up). Also, the echo command will write it to the file as one single big line (newline-codes are lost).
There is a simple solution to solve all this: use the "tee" program.
Instead of what you are trying to do:
Code:
logvar=`rsync -av --stats --progress /srcpath /destpath`
# ...
echo "$logvar" >/path/to/logfile
You can do this to write to a file and stdout (the terminal) at the same time:
Code:
rsync -av --stats --progress /srcpath /destpath | tee /path/to/logfile