I am writing a script to help me sync files between my home pc and my server. One of the problems ive run into is that, when I run the for loop, it outputs blank lines.
Everything else seems to be fine, echo $REMOTE lists all files and their full paths as expected. I have tried unquoting, quoting, Changing EOF from "EOF" to EOF etc, but so far nothing has worked.
Here is the script below:
function uploadDownload()
{
if [ "$1" == "d" ]; then
ssh -i ~/Dropbox/Business/aws/first.pem [email protected] << EOF
echo $REMOTE
for file in $REMOTE; do
echo $file
done
EOF
#scp -r -i ~/Dropbox/Business/aws/first.pem [email protected]:$REMOTE $LOCAL
elif [ "$1" == "u" ]; then
scp -r -i ~/Dropbox/Business/aws/first.pem $LOCAL [email protected]:$REMOTE
fi
}
if [ "$2" == "m" ]; then
if [ -z "$3" ]; then
echo "Please enter the local location of the files and provide an absolute path..."
read LOCAL
echo "Please enter the remote location of the files..."
read REMOTE
uploadDownload
else
LOCAL=$2
if [ -z "$4" ]; then
REMOTE=$3
else
REMOTE='[email protected]:~/test/'
fi
uploadDownload
fi
else
LOCAL='/home/will/Dropbox/Business/aws/files/binaryhustle/'
REMOTE='/home/ubuntu/dev/binaryhustle/*'
uploadDownload $1
fi
EDIT: based on advice I have edited the uploadDownload function. I should also note than I tested echo "$REMOTE"; outside of the loop and it returns nothing (unlike without quotes, where it returns something).
function uploadDownload()
{
if [ "$1" == "d" ]; then
ssh -i ~/Dropbox/Business/aws/first.pem [email protected] << EOF
for file in "/home/ubuntu/dev/binaryhustle"; do
echo $file
done
EOF
#scp -r -i ~/Dropbox/Business/aws/first.pem [email protected]:$REMOTE $LOCAL
elif [ "$1" == "u" ]; then
scp -r -i ~/Dropbox/Business/aws/first.pem $LOCAL [email protected]:$REMOTE
fi
}