LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Bash -- Rsync directory variable has a space (http://www.linuxquestions.org/questions/programming-9/bash-rsync-directory-variable-has-a-space-4175421465/)

KroniK 08-10-2012 04: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: http://pastebin.com/uph49vHd

However the important bit is as follows:

Code:


for ((i=0; i<1; i++))
do
localpath="'/nusdata/staff/NUS/NUS/Systems/${kiskasys[$i]}'"
remotepath="/home/www/html/systems/${websys[$i]}"
rsync -rlptnvz -s "$localpath" -e "ssh -p 50014" "nusak@webserver:$remotepath/"
done

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:

Code:

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!!

Thanks

KroniK 08-10-2012 05: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 09:49 AM

Please mark as SOLVED once you have a solution.


All times are GMT -5. The time now is 05:30 AM.