1

I'm using an existing bash script and want to send the output of 2 rsync commmands so that it is passed to a variable which will then be used later, See below,

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/) && $(rsync -rvlpogt /svnbranch/branches/ /var/www/html/)
ecode=$?
newfil=$(echo $rfiles | grep -c "Number of files transferred: 0")

However, I only get the output of the 1st rsync sent to my mail. How do include the output of the 2nd rsync command as well along with the first?

Thank you.

4

2 回答 2

1

问题在于你的作业是如何写的。它打破了你的路线:

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/) && $(rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

进入rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/) && $(rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

因此,您只得到变量中第一个命令的输出。您需要将命令更改为

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/ && rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

用另一个例子来说明:

samveen@precise:~$ a=$(echo 10) && $(echo 20)
-bash: 20: command not found
samveen@precise:~$ echo $a
10
于 2013-06-17T15:55:29.603 回答
0

您可能希望将这两个命令都放在命令扩展中:

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/ && rsync -rvlpogt /svnbranch/branches/ /var/www/html/)
于 2013-06-17T15:55:04.023 回答