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

Re: bash question



On Sat, Oct 10, 2009 at 01:21:30AM -0500, Boyd Stephen Smith Jr. wrote:
> In <[🔎] 20091010042217.GD2004@samad.com.au>, 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.

Oh well, time to play with IFS or eval

> 
> 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:


I wanted to try and stick to non bashisms

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

thanks

-- 
"We're concerned about AIDS inside our White House -- make no mistake about it."

	- George W. Bush
02/07/2001

Attachment: signature.asc
Description: Digital signature


Reply to: