3

I'm writing a bash script and I need to capture the text resulting from the output of the rsync command, for instance, the following command:

rsync -av "$FOLDER1" "$FOLDER2"

prints:

...
sent 109,423 bytes  received 352 bytes  219,550.00 bytes/sec
...

and I want to capture that line (sent 109,423 bytes received 352 bytes 219,550.00 bytes/sec) and put that string in a variable in my script.

How can I do that?

2 Answers 2

9
variable=$(rsync -av "$FOLDER1" "$FOLDER2" | grep "^sent")
-1

I solved it by doing:

variable=$(rsync -av "$FOLDER1" "$FOLDER2" | tee /dev/tty)

thanks anyway

1
  • 6
    Perhaps you should adjust your question. As it is, Cyrus' answer is correct, and this one is not. Your question mentions nothing about wanting to send the output to the tty in addition to capturing it. Your answer also captures all output, while your question says you just want one line.
    – phemmer
    Sep 7, 2014 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.