0

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)

9
  • 6
    ksh != bash. Try running bash test.sh Commented Feb 13, 2014 at 15:52
  • Can you echo what you x1 is? Guessing quoting "$(echo $x1 | cut -f3 -d" " | cut -f1 -d"]")" might help. Also, you should put ksh as a tag rather than powershell Commented Feb 13, 2014 at 16:10
  • x1 is grep results having some matched sentences Commented Feb 13, 2014 at 16:11
  • Right, but it's clearly trying to execute some ( or other character, which is going to be specific to whatever x1 actually is. So would help if you echoed it. Commented Feb 13, 2014 at 16:14
  • <MSCRI><![CDATA[abc></MSCRI> <MSCRI><![CDATA]></MSCRI> </MSCRI>></MSCRI> Commented Feb 13, 2014 at 16:18

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@logan Short answer: preferably not. ksh88 does still support numeric arrays, but you need to declare and set them with set -A Array arg1 arg2 ... (arg<n> optional). After that you can set individual elements with Array[n]="arg". The number of elements in an array is limit to just over a thousand.
0

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

bash test.sh

5 Comments

Better yet, change the shebang line to #!/bin/bash (or wherever it's installed on Solaris, /opt/public/secret/xpg4/compat/bash?)
Can you explain the "this won't work under ksh" bit?
@broslow bash is not ksh. Some commands might work in both, but not all. You wouldn't expect perl to work if you ran it through the python interpreter. What is there to explain?
@kevin I'm not saying they don't have differences, but bash and ksh both derive from the bourne shell and syntactically I don't see why this won't work in ksh
arrays aren't part of the Bourne shell specification, though. pubs.opengroup.org/onlinepubs/009695399/utilities/… However, it seems that newer ksh versions might have also started supporting the same extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.