[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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


Reply to: