Using the KSH Definition Type
The Korn shell (KSH) is the default UNIX shell on UNIX systems such as AIX, HP-UX, and Solaris. It is also available for Linux and Windows in the form of pdksh
.
Note: You must assign at least one Process Server to run KSH Process Definitions in order to use the KSH Definition Type.
Interpreter
By default, the interpreter for KSH scripts defaults to /bin/ksh
on most platforms. You can override this by specifying a different interpreter (for example, /usr/local/bin/pdksh
) on Process Server level with the LocalInterpreter_KSH
Process Server parameter. You can also specify a list of allowed interpreters on Process Server level using the InterpreterWhitelist_KSH
Process Server parameter and override the default interpreter on Process Definition level with the parameter JCS_INTERPRETER_KSH
. The interpreter must be whitelisted using the InterpreterWhitelist_KSH
Process Server parameter.
The InterpreterWhitelist_KSH
Process Server parameter takes a regular expression that must match the value of the JCS_INTERPRETER_KSH
parameter.
Writing portable KSH scripts
The KSH implementation is not the same on all platforms. Redwood has found the following compatibility issues between these variations.
- Some versions of KSH do not support aliases in non-interactive invocations of the Korn shell. In other implementations, aliases can only be used in scripts that are not sourced, but executed. Since the Process Definition script code is sourced, it cannot call any aliases. Redwood recommends that you use functions instead.
- On Solaris, you cannot use the syntax
$(command)
to execute a program and substitute its standard output. Instead, use a pair of grave (`
) characters to maintain portability with Solaris: ``command.
. pdksh
does not implement all the features of AT&Tksh
, so there are minor differences between the two.- The AT&T Korn shell has been released with an Eclipse Public License, and the source code is freely available on github. This means that most major Linux distributions can now offer AT&T's Korn shell. If you have an older Solaris or Linux system, you might consider building and deploying it.
Environment
For more information about predefined variables and how to create per-system or per-user-environment variables, see Using Platform Definition Types.
The KSH Definition Type will source ${JCS_HOME}/admin/ksh.profile
if it exists, for backwards compatibility with v7. You can set JCS_HOME
with the EnvironmentFile or EnvironmentVariables mechanism, which is documented in Using Platform Definition Types.
Variables and Parameters
- Parameters in a Process Definition are manipulated in the KSH source simply as variables, using the standard
$VARIABLE
syntax. - The Korn shell does not have actual data types. All parameter values are stored as strings. Numbers are translated automatically. Dates are sent and retrieved using the Script Date Format.
- Out parameters are supported. Set an Out parameter using the
VARIABLE=VALUE
syntax. - Array parameters are supported for KSH, provided your interpreter supports them.
Returning an Error
If your script exits with a non-zero exit code, this is correctly reflected in RunMyJobs.
To abort script execution immediately on running a command that has a non-zero exit status, code a set -e
command.
KSH Examples
This example shows how to use a normal environment variable.
echo "This is running under user $USER with home directory $HOME and temporary directory $TMPDIR."
This example shows how to pass numeric (N1
), string (S1
) and date (D1
) parameters to and from KSH scripts.
# Note KSH allows no spaces around = in variable assignment
N1=`expr $N1 + $N1` # Add numeric variable to itself
S1="$S1 $S1" # Concatenate string
echo "Concatenated string" $S1
DTEMP="1999/12/31 23:59:59,000 GMT"
echo You said $D1, I propose $DTEMP
D1=$DTEMP # Set DateTime to new string value
This example shows you how to return a non-zero exit code, resulting in the process going into Error status.
N=1
echo "Exiting with value $N."
exit $N
echo "Not reached"