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 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, like /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, it must exist and be white-listed 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
See Using Platform Definition Types for more information regarding the predefined variables and how to create per-system or per-user environment variables.
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 you interpreter supports them - note that array support in bash requires version 2.0 or higher. Newer versions have more reliable support.
Returning an Error
If your script code exits with a non-zero exit code this is correctly reflected in the server.
Code a set -e
command to abort script execution immediately on running a command that has a non-zero exit status.
BASH Examples
Parameters
The following shows how to use parameters, exposed as environment variables:
echo "This is running under user $USER with home directory $HOME and temporary directory $TMPDIR."
The following shows how to pass numeric (N1), string (S1) and date (D1) parameters to and from BASH scripts:
# 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
The following example shows you how to return a non-zero exit code resulting in the process going into Error:
N=1
echo "Exiting with value $N."
exit $N
echo "Not reached"
Array handling
myArray=(One Two Three)
for t in ${myArray[@]}; do
myOutArra]y+=( $t )
done