rsync question

Karl Auer kauer at biplane.com.au
Sun Nov 2 22:09:07 UTC 2014


On Sun, 2014-11-02 at 20:55 +0000, R Kimber wrote:
> >    rsync .... 2>&1 | grep -v "ignoring unsafe symlink"
> But if I do [ $? -ne 0 ] is it rsync or grep that returns the value?

Both return a value, but it is grep's that will be placed in $?. $?
"expands to the exit status of the most recently executed foreground
pipeline."

If you want to check rsync's return value instead (or as well) you will
have to execute the two parts separately:

TEMPFILE=/tmp/$$
rsync ... > $TEMPFILE 2>&1
RSYNCVAL=$?
grep ... $TEMPFILE > /dev/null 2>&1
GREPVAL=$?
rm $TEMPFILE
(...do things with $RSYNCVAL and $GREPVAL...))

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer
http://twitter.com/kauer389

GPG fingerprint: EC67 61E2 C2F6 EB55 884B E129 072B 0AF0 72AA 9882
Old fingerprint: B862 FB15 FE96 4961 BC62 1A40 6239 1208 9865 5F9A






More information about the ubuntu-users mailing list