Problem passing file name with spaces to shell script

A part of my python script calls a shell script ( and passes variables.

Problem is with var3 which is a file name. If it contains spaces, doesn't get the entire string.

var3 = "/app/interface/exports/TEST5191 326150.txt"

My question is how to send var3 - imbedded spaces and all?

irtn = os.system("./ %s %s %s %s " % (var,var1,var2,var3))

This is the code from sfile accepts parameter #4, the file name(sfile).



# Variables below


rsync -avz -e "ssh -p 22 -i /home/testusr/.ssh/key1 " $sfile rsyncadmin@$remotehost:$dest
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this:


rsync -avz -e "ssh -p 22 -i /home/testusr/.ssh/key1 " "$sfile" rsyncadmin@$remotehost:$dest  

Please note the double quotation marks around "$4" and "$sfile"!
I don't know Python at all - could it be that those double quotes can/must be applied here, too ("var3")?

irtn = os.system("./ %s %s %s %s " % (var,var1,var2,"var3"))

Or does the above keep Python from interpreting "var3" as a variable name? Sorry for the stupid suggestion then!
Put the double quotes inthe format string, with single quotes round the entire string, so have:

    irtn = os.system('./ %s %s %s "%s"' % (var,var1,var2,var3))

(forgot to say, you need wmp's changes to the shell script too)
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

nighter33Author Commented:
Thanks for the suggestions but same error -only passes the first part of the file name up to the first space in both cases..
Did you make the changes I suggested to the bash code? They're required, regardless of what you're doing with the Python code!
nighter33Author Commented:
My error. I made both changes and it works!
Thank you very much.
nighter33Author Commented:
Response was very quick.
If you made both changes, why did you accept only one answer?
I agree - wmp and I gave half the answer each!
nighter33Author Commented:
Sorry, new to this. Can I correct?
Click "Request Attention" and ask the moderators (along with a short explanation) to reopen the question.

Then follow these guidelines:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.