syntax error issue while storing array value Unix Solaris Korn Shell

瘦欲@ 提交于 2019-12-25 02:49:37

问题


Here is my command in shell script.

x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]"))

syntax error at line 818 : `(' unexpected

If I remove this line its working

Note: The same script runs in Linux OS when i try it in Solaris it throws error.


回答1:


It depends on your ksh version:

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



回答2:


execute below one it will work..using ksh..

x1="test1 test2 test3]testarray test"
x="$(echo $x1 | cut -f3 -d" " | cut -f1 -d"]")"
echo $x


来源:https://stackoverflow.com/questions/21757669/syntax-error-issue-while-storing-array-value-unix-solaris-korn-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!