Re: bash question



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/"

with sh -x i get this

+ rdiff-backup --remote-schema ''\''ssh' -i /root/.ssh/id_backup -C %s rdiff-backup '--server'\''' --remove-older-than '"10B"' --force max::/backups/test/system/

I am pretty sure you are using bash as the sh link, do 'ls -la /bin/sh' to get: /bin/sh --> /bin/bash
If it were dash the responses would be different.

Testing: set up a "test" file with:
#!/bin/sh
RDSCHM="--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'"
echo $RDSCHM
echo "$RDSCHM"
with: bash -x test, I get:
+ RDSCHM='--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'\'''
+ echo --remote-schema ''\''ssh' -i /root/.ssh/id_backup $'-C\302\240%s' 'rdiff-backup --server'\'''
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
+ echo '--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'\'''
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'

with: dash -x test, I get:
+ RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
+ echo --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
+ echo --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'

with dash there is no « ''\''ssh' »

Also, did you notice the difference between a command on an unquoted variable and a quoted one?
+ echo --remote-schema ''\''ssh' -i /root/.ssh/id_backup $'-C\302\240%s' 'rdiff-backup --server'\'''
+ echo '--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'\'''

Conclusion: Quoting the variable will solve your problem, as this:
rdiff-backup \
"$RDSCHM" \
"$RDRM" \
"$DEST/"


the ''\''ssh' is the confusing bit it is seperate out the ssh and the -i.

Yes, on a bash shell, but only while quoting with -x, the actual command does the right thing.

what can I do to prevent this.

Just put « $RDSCHM » inside quotes as this: « "$RDSCHM" »

My reading has lead me to IFS variable
but I don't want to start playing with this yet ! I think I am just
missing something. Hopefully the ml eyes will be able to see what i
can't

No need to....

oh and its using dash well sh

It does not really matter which shell it is, when the issue is about correct quoting of variables.

--
Antonio Perez


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: [semi-OT] How to echo \ in dash
    ... In an effort to write my scripts in a posix conform way, ... dash instead of bash. ... Per the POSIX and SUS specifications, the echo command, which maybe be built ...
    (Debian-User)
  • [semi-OT] How to echo \ in dash
    ... dash instead of bash. ... It's a bit confusing that one cannot echo two \\ to another file. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: bash -> dash translation
    ... I recently got bitten by the change from bash to dash as the default ... cmd { ... echo 1 +bar=2 ...
    (comp.unix.shell)
  • Re: which package a file belongs to
    ... it works in dash and bash. ... in zsh, my favorite shell. ... echo hello | echo $ ...
    (Ubuntu)
  • Re: running a simple command line tool
    ... bash but not in the 'sh' that it's a development from). ... modern Ubuntus and Debians use dash instead (in the interests of ... - something expecting the bourne shell will work in bash. ...  Unable to execute command: 'sh test.sh' ...
    (Ubuntu)