Question

I am execution following .sh file in solaris box its not working but if i execute as command line, its working

bash-3.00$ ksh test.sh 
ksh test.sh 
test.sh[3]: syntax error at line 3 : `(' unexpected

test.sh is (not working)

#!/bin/ksh 
x1=`grep -i "\abc" /UC/*.*` 
x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]"))

Manual Execution: (working fine)

bash-3.00$ x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]"))
x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]"))
echo $x1 | cut -f3 -d" " | cut -f1 -d"]"
bash-3.00$ echo ${x[0]}
echo ${x[0]}
GOOD Boy
bash-3.00$

Solaris Verison:

GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)

Was it helpful?

Solution

The ksh (there's more than one) in this case is the old Solaris ksh88 as *(/usr)/bin/ksh, which was the default ksh until (and including) Solaris 10.

AT&T open-sourced ksh93 back in 2002 or so, which was adopted later into linux and various OpenSolaris derivatives.

ksh93 and bash are quite close, and their developers have kept in touch and contributed to the POSIX shell standardisation effort.

The array assignment x=( ... ) is supported in both ksh93 and bash, not in ksh88, where it results in the above syntax error.

how to solve this problem in ksh88 -- @logan

In ksh88 you can try:

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

Finally, there have been alternative implementations like mksh and the commercial MKS. I think the latter may actually share some code with the originals ksh88 from the AT&T Toolchest in the '80s. The MirBSD Korn shell, or mksh is the successor of the abandoned pdksh project.

OTHER TIPS

This won't work under ksh. Run it using bash:

bash test.sh
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top