Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-10-2012, 04:29 PM   #1
LQ Newbie
Registered: Aug 2012
Posts: 13

Rep: Reputation: Disabled
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!!

Old 08-10-2012, 05:37 PM   #2
LQ Newbie
Registered: Aug 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
Found the error.

the above is correct, i just needed to remove the single quotes in the localsys variable...
Old 08-11-2012, 09:49 AM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 8,308

Rep: Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251Reputation: 2251
Please mark as SOLVED once you have a solution.


bash, directory, rsync, spaces, variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 03:29 PM
bash script: use the directory of the script file as variable? phling Linux - Newbie 12 01-16-2010 08:16 PM
Script to copy specific directory based on variable to folder with that variable name fluxburn Programming 7 01-07-2010 08:59 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 02:15 PM
How do you assign a variable to be a variable file name in a directory? David_Elliott Programming 4 04-14-2009 11:19 AM

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration