我有一个带有以下输出的 Java 类:
"Roses are red" "Violets are blue" "Daisies are white"
我正在尝试创建一个执行此 Java 类的 KornShell (ksh) 脚本,将结果存储到一个数组中,然后输出
Roses are red
Violets are blue
Daises are white
这是我第一次尝试脚本:
1 #!/bin/ksh
2
3 set -A colors $(java Colors)
4
5 for i in "${colors[@]}"
6 do
7 echo "$i"
8 done
但是,输出如下所示:
"Roses
are
Red"
"Violets
are
blue"
"Daisies
are
white"
当我抛出:
echo set -A colors $(java Colors)
进入脚本以查看正在调用的内容,它返回:
set -A colors "Roses are Red" "Violets are blue" "Daisies are white"
如果我用上面的第 3 行替换那个确切的输出,我会得到所需的输出:
Roses are red
Violets are blue
Daises are white
为什么命令替换会把整个事情扔掉?
如果有帮助,下面是 Java 类:
public class Colors {
public static void main(String[] args) {
System.out.println("\"Roses are Red\" \"Violets are blue\" \"Daisies are white\"");
}
}