Re: bash question



In <20091010042217.GD2004@xxxxxxxxxxxx>, Alex Samad wrote:
Hi

i have this

RDSCHM="--remote-schema 'ssh -i /root/.ssh/id_backup -C %s
rdiff-backup --server'"


and trying this

rdiff-backup \
$RDSCHM \
$RDRM \
"$DEST/"

Sorry, there's no clean, portable way to have both multiple command-line
arguments in a single variable and have an IFS character in one of those
arguments.

When you do this rdiff-backup gets these arguments:
argv = {
[0] = "rdiff-backup"
[1] = "--remote-schema"
[2] = "'ssh"
[3] = "-i"
[4] = "/root/.ssh/id_backup"
[5] = "-C"
... /* etc. */
}

If you force your script to be executed with bash (NOT dash or just sh) you
can use shell arrays to do what you want:

RDSCHM=(
'--remote-schema'
'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
)

rdiff-backup \
"$RDSCHM[@]" \
$RDRM \
"$DEST/"


You can also force your to work correctly under dash / sh, but you'll have to
understand how to use eval, which can get a bit tricky. It would look
something like this:

RDSCHM="--remote-schema \
'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'"

eval "rdiff-backup $RDSCHM $RDRM "'"$DEST/"'
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@xxxxxxxxxxxxxxxxx ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/

Attachment: signature.asc
Description: This is a digitally signed message part.



Relevant Pages

  • Re: bash question
    ... If it were dash the responses would be different. ... echo "$RDSCHM" ... Yes, on a bash shell, but only while quoting with -x, the actual command does the right thing. ...
    (Debian-User)
  • Re: bash question
    ... If it were dash the responses would be different. ... did you notice the difference between a command on an unquoted variable and a quoted one? ... Yes, on a bash shell, but only while quoting with -x, the actual command does the right thing. ...
    (Debian-User)
  • Re: bash question
    ... Sorry, there's no clean, portable way to have both multiple command-line ... arguments in a single variable and have an IFS character in one of those ... When you do this rdiff-backup gets these arguments: ... You can also force your to work correctly under dash / sh, ...
    (Debian-User)