Using the BASH Definition Type

The BASH shell is the default UNIX shell on Linux, and is usually available on other UNIX systems such as AIX, HP-UX and Solaris. Various ports also exist for Microsoft Windows.

Note: You must assign at least one Process Server to run BASH definitions in order to use the BASH Definition Type.

Interpreter

By default, the interpreter for BASH scripts defaults to /bin/bash on most platforms. You can override this by specifying the full path to an interpreter on Process Server-level with the LocalInterpreter_BASH Process Server parameter, setting it to (for example) /usr/local/bin/bash. You can also specify a list of allowed interpreters on Process Server-level using the InterpreterWhitelist_BASH Process Server parameter, and override the default interpreter on Process Definition-level with the parameter JCS_INTERPRETER_BASH. Simply create the parameter and point it to your preferred interpreter. The parameter must be whitelisted using the InterpreterWhitelist_BASH Process Server parameter.

The InterpreterWhitelist_BASH Process Server parameter takes a regular expression that must match the value of the JCS_INTERPRETER_BASH parameter.

Environment

For more information about predefined variables and how to create per-system or per-user environment variables, see Using Platform Definition Types.

In addition, the BASH Definition Type will source ${JCS_HOME}/admin/bash.profile if it exists, for backwards compatibility with v7. You can set JCS_HOME with the EnvironmentFile or EnvironmentVariables mechanism documented in Using Platform Definition Types.

Variables and Parameters

  • Parameters in the definition are manipulated in the BASH source simply as variables, using the standard $PARAMETER syntax.
  • The BASH 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 by setting the parameter using the PARAMETER=VALUE syntax.
  • Array parameters are supported, provided your interpreter supports them. Note that array support in bash requires version 2.0 or higher. Newer versions have more reliable support. Arrays must have unique elements.

Returning an Error

If your script code results in a non-zero exit code, this is correctly reflected in the server. Code a set -e command to abort script execution immediately upon running a command that has a non-zero exit status.

BASH Examples

Parameters

This example shows how to use parameters, exposed as environment variables.

Copy
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 BASH scripts.

Copy
# Note BASH allows no spaces around = in variable assignment
N1=$((expr $N1 + $N1))  # Add numeric variable to itself
S1="$S1 $S1"  # Concatenate string
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.

Copy
N=1
echo "Exiting with value $N."
exit $N

echo "Not reached"

Array Handling

This example shows how to handle arrays.

Copy
myArray=(One Two Three)
for t in ${myArray[@]}; do
  myOutArra]y+=( $t )
done