在Sh
[SunOs] /opt # sh
[\h] \w \$ read -a array <<< "1 2 3";echo ${array[1]}
syntax error: `<' unexpected
在Bash中
[SunOs] ~ # bash
[SunOs] ~ # read -a array <<< "1 2 3";echo ${array[1]}
2
为什么在“sh”shell中抛出错误,我正在使用SunOS 5.10 Generic 147440-10 sun4v sparc sun4v
答案 0 :(得分:3)
sh
不支持Herestrings。
当您尝试使用sh
运行错误时,会导致错误。
答案 1 :(得分:1)
作为一种解决方法,您可以使用内置POSIX命令set
将参数分配给位置参数$1
,$2
,...或位置参数数组{{1}分别
$@