Unpopulated variable causes Linux script to run in background

Document ID : KB000099972
Last Modified Date : 04/06/2018
Show Technical Document Details
Introduction:
The issue is described by the following scenario:

A Linux job should execute a command like the following in a shell:
 
User-added image

The variable &variable# should normally be populated in the Pre-Process of the job, e.g. with the date:
 
User-added image

The script SomeShellScript.sh is a simple script with only this content:
 
User-added image

I.e., the following command will be executed in Linux:
 
./SomeShellScript.sh 180604

The resulting report shows, the input variable is passed to the script and displayed:
 
User-added image

It might happen that the variable is not populated. E.g. you populate the variable &variable# not like in the example above, but is some script with e.g. IF-conditions. In this case, the command executed in Linux is:
 
./SomeShellScript.sh &variable#

The report now shows the following:
 
User-added image

The job ends with:
 
User-added image

Nevertheless, as can be seen in the report, the script was executed without the variable. Remarkable: The Output of the script is written after the Job ended statement of the job messenger.

Fazit: The job ends with ENDED_NOT_OK - aborted, but the script is executed. When e.g. an operator sees the job status, he/she might start the job again and the shell-script is executed twice. For some customers, this can cause problems.
Background:
If a single trailing ampersand (&) in a Linux command that is executed in a shell, the execution of this command is set to a sub-shell in the background. I.e, in this special case, the ampersand at the beginning of the variable &variable# is interpreted as a trailing ampersand and the execution is sent in the background to a subshell.
Instructions:
This can be easily avoided by using single quotes
 
User-added image

Executing it correctly with a populated variable, the report looks like:
 
User-added image

If &variable# is unpopulated, the report looks like:
 
User-added image