spaces in include/exclude/source

Asked by Will Torres

Can't seem to pass directories with spaces. Have tried surrounding with quotes, and escaping space, but i get "expected 2, got 20" arguments

Question information

Language:
English Edit question
Status:
Solved
For:
Duplicity Edit question
Assignee:
No assignee Edit question
Solved by:
Will Torres
Solved:
Last query:
Last reply:
Revision history for this message
Will Torres (wtorres) said :
#1

Version 0.6.20

Revision history for this message
edso (ed.so) said :
#2

did you try to escape the space chars with backslash?

e.g. foo bar -> foo\ bar

..ede/duply.net

Revision history for this message
edso (ed.so) said :
#3

please also post your complete commandline.. ede/duply.net

Revision history for this message
Will Torres (wtorres) said :
#4

yes, i've tried encapsulating with quotes, as well as escaping the spaces.

the command itself works if i type it manually, but it doesn't work through a bash script.

i'm not really sure where to go with this now! :P

Revision history for this message
Will Torres (wtorres) said :
#5

well, it seems i have to run it through eval for it to work.

Revision history for this message
edso (ed.so) said :
#6

On 27.11.2012 17:35, Will Torres wrote:
> Question #215356 on Duplicity changed:
> https://answers.launchpad.net/duplicity/+question/215356
>
> Status: Open => Solved
>
> Will Torres confirmed that the question is solved:
> well, it seems i have to run it through eval for it to work.
>

no you don't ... but i see now that this is a general "how to shell script" issue and has nothing to with duplicity itself.

try something like

PARAMS="--param1 'foo bar' --param2 'bla blup'"

duplicity $PARAMS

understand that your shell uses the outer double quotes to understand that you want everything within to be assigned to var PARAM. after that they are gone. so in order for the quotes to survive until used you have to quote within quotes.

if that doesn't work, show me your script and i'll show you your error.

..ede/duply.net

Revision history for this message
Will Torres (wtorres) said :
#7

haha, i did

params="--exclude \"not this\" --include \"this and that\""

then duplicity $params. obviously, this should work. it's worked with million of other things.

i guess i can try apostrophes, instead of the quotes.

Revision history for this message
Will Torres (wtorres) said :
#8

params="--exclude 'this dir' --include 'that dir'"

duplicity $params

no work

Revision history for this message
edso (ed.so) said :
#9

On 27.11.2012 18:11, Will Torres wrote:
> Question #215356 on Duplicity changed:
> https://answers.launchpad.net/duplicity/+question/215356
>
> Will Torres posted a new comment:
> haha, i did
>
> params="--exclude \"not this\" --include \"this and that\""
>
> then duplicity $params. obviously, this should work. it's worked with
> million of other things.
>
> i guess i can try apostrophes, instead of the quotes.
>

pretty much identical, though single quotes should be preferred as they tell your shell to _not_ interpret whatever is between them .. e.g. imagine: '$PATH' would not be expanded to the value but "$PATH" would.

so actually
 params='--exclude \'not this\' --include \'this and that\''
would be the perfect answer.

..ede/duply.net

Revision history for this message
Will Torres (wtorres) said :
#10

i forgot to mention, this is through cygwin :P

i wonder if cygwin path expansion is doing something funky.

Revision history for this message
edso (ed.so) said :
#11

On 27.11.2012 18:56, Will Torres wrote:
> Question #215356 on Duplicity changed:
> https://answers.launchpad.net/duplicity/+question/215356
>
> Will Torres posted a new comment:
> i forgot to mention, this is through cygwin :P
>
> i wonder if cygwin path expansion is doing something funky.
>

nope. just doublechecked..

A. the splitting occurs already before parameters are given to python
B. eval seems to be the workaround (that's also what i do in duply)

see also
http://stackoverflow.com/questions/9982573/pass-shell-escaped-string-of-arguments-to-a-subcommand-in-bourne-shell

..have fun.. ede/duply.net

Revision history for this message
edso (ed.so) said :
#12

On 27.11.2012 19:11, edso wrote:
> Question #215356 on Duplicity changed:
> https://answers.launchpad.net/duplicity/+question/215356
>
> edso posted a new comment:
> On 27.11.2012 18:56, Will Torres wrote:
>> Question #215356 on Duplicity changed:
>> https://answers.launchpad.net/duplicity/+question/215356
>>
>> Will Torres posted a new comment:
>> i forgot to mention, this is through cygwin :P
>>
>> i wonder if cygwin path expansion is doing something funky.
>>
>
> nope. just doublechecked..
>
> A. the splitting occurs already before parameters are given to python
> B. eval seems to be the workaround (that's also what i do in duply)
>
> see also
> http://stackoverflow.com/questions/9982573/pass-shell-escaped-string-of-arguments-to-a-subcommand-in-bourne-shell
>
> ..have fun.. ede/duply.net
>

also here is some more nifty background
http://www.greenend.org.uk/rjk/tech/shellmistakes.html

the following seems to be a way around using the potentially unsafe 'eval'

set -- '--foo' 'bar baz' 'qux'
command "$@"

of course you should have interpreted all parameters befor overwriting them in your script.

--ede

Revision history for this message
Will Torres (wtorres) said :
#13

awesome.

also saw that i could make the arguments be part of an array. might not be a bad idea!