bash - build command string and execute it

I’m trying to set up a bash script to run rsync with various parameters

I build up $CMD by adding the various arguments by

CMD="$CMD --verbose"

and then execute the command as simply

$CMD

What’s not working is adding in

CMD="$CMD --log-file-format=’${RUN_ID} %i %n %l’"

It’s the spaces in ‘${RUN_ID} %i %n %l’ that cause the problem - if I take
them out I don’t get an error but the single quotes get put in the log.

I’ve tried various things (escaping the quotes, the spaces etc.) but now I’m
stuck and there’s a dent in the wall the size and shape of my forehead.

Can someone help me out here please.

Alan

Fudokai wrote:

> I’m trying to set up a bash script to run rsync with various parameters
>
> I build up $CMD by adding the various arguments by
>
> CMD="$CMD --verbose"
>
> and then execute the command as simply
>
> $CMD
>
> What’s not working is adding in
>
> CMD="$CMD --log-file-format=’${RUN_ID} %i %n %l’"
>
> It’s the spaces in ‘${RUN_ID} %i %n %l’ that cause the problem - if I take
> them out I don’t get an error but the single quotes get put in the log.
>
> I’ve tried various things (escaping the quotes, the spaces etc.) but now
> I’m stuck and there’s a dent in the wall the size and shape of my
> forehead.
>
> Can someone help me out here please.
>
> Alan

Ok, Ok - use eval

Why is it I only find the answer to a problem 5 minutes after I’ve asked a
dumb question?

Alan

That’s just Murphy at work. If you hadn’t asked the question, the answer wouldn’t have come to you. :wink: