-   Programming (
-   -   Bash -- Rsync directory variable has a space (

KroniK 08-10-2012 03:29 PM

Bash -- Rsync directory variable has a space
So I am writing a bash script to automatically rsync around 40 different directories to 40 other directories on another server.

If you want to read my whole script you can find it here:

However the important bit is as follows:


for ((i=0; i<1; i++))
rsync -rlptnvz -s "$localpath" -e "ssh -p 50014" "nusak@webserver:$remotepath/"

Where kiskasys is an array of directory names and websys is an array of corresponding directory names.

The problem is that kiskasys is full of directory names with spaces.

Now I can easily change how those directory names are put into the array, say by adding escaped spaces like '\ ' or by adding quotes around it etc but i have tried all different combinations of this and still have yet to make it work.

Here is an example of what the rsync command would look like if i didnt use variables:


rsync -rlptnvz -s "nusdata/staff/NUS/NUS/Systems/101 greenbrook/" -e "ssh -p 50014" "nusak@webserver:/foo/bar"
note that the only directory with spaces would be the local directory.

Any help on how to make this work would be appreciated!!


KroniK 08-10-2012 04:37 PM

Found the error.

the above is correct, i just needed to remove the single quotes in the localsys variable...

grail 08-11-2012 08:49 AM

Please mark as SOLVED once you have a solution.

All times are GMT -5. The time now is 12:48 AM.