2

I'm trying to simply sync a folder using rsync over my local network from my computer in front of me to the destination computer.

#!/bin/bash

echo "This script will sync from my Macbook Dropbox/scripts/ folder to ruth@10.0.0.9 @ Norms house"

OPTIONS="--recursive --ignore-existing --progress"
SRC_DIR="~/Dropbox/scripts/"
DST_DIR="ruth@10.0.0.9:~/scripts/"
rsync "$OPTIONS" "$SRC_DIR" "$DST_DIR"

To give myself write privileges

chmod +x nameofscript.sh

When I run it, it outputs:

rsync: --recursive --ignore-existing --progress: unknown option

How do I properly store these options and run it as a script?

  • 1
    Please don’t add your solution to your question; if you feel the accepted answer isn’t complete enough, you can suggest an edit to that, or add your own separate answer. – Stephen Kitt Mar 22 '18 at 22:16
3

By quoting "$OPTIONS", the shell is passing it to rsync as a single string, so rsync is trying to find a single option named "--recursive --ignore-existing --progress", which obviously doesn't exist, since these are three separate options.

This should fix it for you:

rsync $OPTIONS "$SRC_DIR" "$DST_DIR"

A better option might be to use a bash array to store your options.

OPTIONS=(
    --recursive
    --ignore-existing
    --progress
)
# ...
rsync "${OPTIONS[@]}" "$SRC_DIR" "$DST_DIR"

The advantage of using an array is that then you are able to introduce items that include spaces, if any are necessary.

  • The bash array works great to store the options, I've edited my original with the correct script. Thank you. – Kaiya Mar 22 '18 at 21:55
  • Awesome @Kaiya, I'm glad this worked for you! – filbranden Mar 22 '18 at 22:06

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.