Results 1 to 3 of 3

Thread: bash - build command string and execute it

  1. #1
    Join Date
    Jun 2008
    Location
    Norwich, UK
    Posts
    222

    Default 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

  2. #2
    Join Date
    Jun 2008
    Location
    Norwich, UK
    Posts
    222

    Default Re: bash - build command string and execute it [SOLVED]

    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

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: bash - build command string and execute it

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •