0

I am trying to execute one .sh script in AIX environment, but it's giving an error at below line

tableList = ( Value1 Value2 Value3 )

I have tried executing the script like below:

  1. sh file1.ksh
  2. I renamed the file to .ksh then executed the file sh ./file1.sh
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • there are no such things as file extensions in Unix: it is just part of the file name. To make it use a different shell you need to run it with a different shell. A cool way to do this is with a #! as the first line of the script. e.g. #!/bin/sh, #!/bin/ksh or #!/bin/bash. Then make the file executable. – ctrl-alt-delor Nov 16 '19 at 17:19
  • See also: Spaces in variable assignments in shell scripts. This is also one of those cases where the error message might actually point in the direction of at least the immediate problem. – ilkkachu Nov 16 '19 at 19:21

2 Answers2

3

The sh shell don't generally understand arrays as they are not part of the POSIX standard. The filename of the script is arbitrary, so a .sh or a .ksh filename suffix means nothing whatsoever.

Also, your array assignment syntax is a bit wrong (too many spaces). Corrected, it would look like

tableList=( Value1 Value2 Value3 )

Note the lack of blanks between the end of the variable's name and the (.

To be able to run your script, you would need to execute it with a shell that implements arrays, such as ksh93, bash, zsh, or yash (depending what other shell constructs you are using). Note that ksh on AIX is ksh88 which has a slightly different syntax for assigning values to arrays (it uses set -A tableList Value1 Value2 Value3).

The best way of running your script with ksh93 is to add a #!-line to the top of the script, pointing to the ksh93 interpreter, and then make the script executable with chmod +x scriptname.

To use the ksh93 shell on AIX, the very first line of the script should look like

#!/usr/bin/ksh93

After that, don't specify an explicit interpreter on the command line when you run the script:

./scriptname
Kusalananda
  • 333,661
0

AFAIR, AIX uses a ksh88 based POSIX shell as /bin/sh

ksh88 does not support

tableList=( Value1 Value2 Value3 )

and this is not required by POSIX.

schily
  • 19,173