nested if: too many arguments?

Posted by FLX on Stack Overflow See other posts from Stack Overflow or by FLX
Published on 2011-02-04T10:05:14Z Indexed on 2011/02/04 15:25 UTC
Read the original article Hit count: 351

Filed under:
|

For some reason this code creates problems:

source="/foo/bar/"
destination="/home/oni/"

if [ -d $source ]; then
        echo "Source directory exists"
        if [ -d $destination ]; then
                echo "Destination directory exists"
                rsync -raz --delete --ignore-existing --ignore-times --size-only --stats --progress $source $destination
                chmod -R 0755 $destination
        else
                echo "Destination directory does not exists"
        fi
else
        echo "Source directory does not exists"
fi

It errors out with:

Source directory exists
/usr/bin/copyfoo: line 7: [: too many arguments
Destination directory does not exists

I used nested if statements in bash before without a problem, what simple mistake am I overlooking?

Thanks!

© Stack Overflow or respective owner

Related posts about bash

Related posts about shell