问题
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