使用<<<在sh shell上抛出错误而不是bash

时间:2014-01-22 10:40:17

标签: bash sh sunos

在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

2 个答案:

答案 0 :(得分:3)

sh不支持Herestrings。

当您尝试使用sh运行错误时,会导致错误。

答案 1 :(得分:1)

作为一种解决方法,您可以使用内置POSIX命令set将参数分配给位置参数$1$2,...或位置参数数组{{1}分别

$@