quoting hell - help needed!!

I am writing a bash script to automate the installation of web environment on a base install of Fedora. And I'm at the limit of my last nerve and my bash skills. My brain is screaming at me: "Give up and use perl", but I am trying to stick to bash since the script will modify the perl environment as it runs.

My challenge, or at least my current one, is illustrated in the following code:

function exec_cmd {
        # code removed for sanity checking and loging
        local CMD="$1"
        local OUT
        OUT=`$CMD >> $LOG 2>&1`
        # code removed for logging and tracking
        return 0
}
 
for i in Xfce 'Development Libraries' 'Development Tools' 
         'MySQL Database' 'Perl Development' 'XFCE Software Development'
do
        CMD="$YUM -y groupinstall $i"
        exec_cmd "$CMD"
done

The code works fine on the first interation through the for loop since Xfce does not contain a space; however, when it reaches 'Development Libraries' and the subsequent multi-word itmes in the list, by the time it gets to executing in exec_sum, 'Development Libraries' is parsed as two separate words. Grrrr

I have tried every quoting approach that I can think of to make this work and all fail, one way or another.

Any help that you can lend will be greatly appreciated!!

lbe

Do you really need a separate function for exec_cmd?
I would write it like this:

_packages=(
  Xfce
  'Development Libraries'
  'Development Tools'
  'MySQL Database'
  'Perl Development'
  'XFCE Software Development'
  ) 
 
for p in "${_packages[@]}"; do 
        "$YUM" -y groupinstall "$p" >> "$LOG" 2>&1
done

Yes, the function handles error tracking and checkpointing for restarts as well as just logging.

See if this works:

for i in Xfce 'Development Libraries' 'Development Tools' \
         'MySQL Database' 'Perl Development' 'XFCE Software Development'
  do
  CMD="$YUM -y groupinstall \"$i\""
  exec_cmd "$CMD"
done

Sorry, no go either. Once function exec_cum a multi-word gets parsed to '"Development' 'Libraries"'

---------- Post updated at 01:42 PM ---------- Previous update was at 01:03 PM ----------

Thanks to all of you who are trying to help.

The following is a small test that you can run on your system, as long as it has yum installed, to replicate my problem and test your recommendation. Instead of performing a groupinstall, it will just list information about the group when working :wink:

#!/bin/bash -x
function exec_cmd {
        local CMD="$1"
        local OUT
        OUT=`$CMD`
        return 0
}
 
for i in Xfce 'Development Libraries' 'Development Tools' 
do
        CMD="yum groupinfo \"$i\""
        exec_cmd "$CMD"
done

Thanks again!

Try:

OUT=$(eval "$CMD")

You sir, are a scholar and a gentleman!!! That works!!!

One last update - I formatted the multi-word items in the list as "'Development Tool'". That and the change recommended above was all it took