Q: ksh command subsitution with quotes into array I have a Java class with the following output:
"Roses are red" "Violets are blue" "Daisies are white"

I am trying to create a KornShell (ksh) script that executes this Java class, stores the result into an array, and then outputs 
Roses are red
Violets are blue
Daises are white

This is my first attempt at the script:
1 #!/bin/ksh
2 
3 set -A colors $(java Colors)
4 
5 for i in "${colors[@]}"
6 do
7     echo "$i"
8 done

However, the output looks like this:
"Roses
are
Red"
"Violets
are
blue"
"Daisies
are
white"

When I throw:
echo set -A colors $(java Colors)

into the script to see what is being called, it returns: 
set -A colors "Roses are Red" "Violets are blue" "Daisies are white"

If I replace that exact output with line 3 from above, I get the desired output:
Roses are red
Violets are blue
Daises are white

Why does the command substitution throw the whole thing off?
Below is the Java class if that helps:
public class Colors {
    public static void main(String[] args) {
        System.out.println("\"Roses are Red\" \"Violets are blue\" \"Daisies are white\"");
    }   
}


A: So I ended up making it work by throwing an 'eval' in front of the set command. It looked like this:
1 #!/bin/ksh
2 
3 eval set -A colors $(java Colors)
4 
5 for i in "${colors[@]}"
6 do
7     echo "$i"
8 done

I'm not sure why that worked exactly, but it did.

A: You may use quotes on $( ) :
set -A colors "$(java Colors)"

to avoid word splitting

A: pass the output of your java command as arguments to another shell script.
Then it will give $1=>"Roses are red",$2=>"Violets are blue", and so on.
you can get hold of all the input arguments using $@

A: This sort of thing is distressingly hard to do.  This seems to work:
$ cat roses
echo '"Roses are red" "Violets are blue" "Daisies are white"'
$ IFS='
> '                                       
$ set -A colors $(eval printf '%s\\n' $(./roses))
$ printf "%s\n" "${colors[@]}"                   
Roses are red
Violets are blue
Daisies are white
$ 

The script ./roses does the same job as your Java class.  The variable IFS is the inter-field separator string; it is set to a newline (only).  The set line creates an array colors.  The value is what you get from executing and capturing eval printf '%s\\n' $(./roses).  The second printf statement prints the elements of the array one per line.
Tested with ksh on Mac OS X 10.8.4.
An equivalent in bash is:
$ IFS='
> '
$ colors=($(eval printf '%s\\n' $(./roses)))
$ printf "%s\n" "${colors[@]}"
Roses are red
Violets are blue
Daisies are white
$

Depending a bit on the version of bash, there are probably other ways to do it too.
You should save and restore the value of $IFS before trampling it.
$ old_ifs="$IFS"
$ IFS='
> '
$ ...use the modified value...
$ IFS="$old_ifs"
$

