这是我在 shell 脚本中的命令。
x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]"))
syntax error at line 818 : `(' unexpected
如果我删除此行,它的工作
注意:相同的脚本在 Linux 操作系统中运行,当我在 Solaris 中尝试时,它会抛出错误。
最佳答案
这取决于您的 ksh 版本:
ksh93
$ ksh --version
version sh (AT&T Research) 93u+ 2012-08-01
$ x1="one two three]four"
$ x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]"))
$ echo ${x[0]}
three
ksh88
$ what /usr/bin/ksh
/usr/bin/ksh:
Version M-11/16/88i
SunOS 5.8 Generic 110662-24 Apr 2007
$ x1="one two three]four"
$ x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]"))
ksh: syntax error: `(' unexpected
关于linux - 存储数组值时出现语法错误问题 Unix Solaris Korn Shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21757669/