How do I set a variable with the output of rsync while keeping the format

Viewed 322

I'm making a shell script that does an rsync

I want to set a variable with the output I get from rsync --stats

If I run the variable in the terminal, the output is displayed on multiple lines

If I do it in my script:

#!/bin/bash
OUTPUT=$(/usr/bin/rsync -az --stats -h SOURCE DESTINATION)

echo -e "$OUTPUT"

Then, the output I get is all multiple lines concatenated in one line

How do I keep the formatting I get when I run the command in the terminal ?

1 Answers

use this script

#!/bin/bash

DIR_TMP=/tmp/test.txt
/usr/bin/rsync -az --stats -h SOURCE DESTINATION >> $DIR_TMP
OUTPUT=$(cat $DIR_TMP)
rm $DIR_TMP

echo -e "$OUTPUT"
Related