This article discusses three possible causes for the Shell error.
Problem:
From within a COBOL program the "system" command is executed to run a program, but the program is not being executed at all. Before it can execute an error is being generated: sh: 0403-057 Syntax error at line 1 : `(' is not expected. There is no bracket in the shell program so what is the problem?
STRING "sh myshell.sh"
DELIMITED BY SIZE
PRTNAME DELIMITED BY SIZE " "
PRINT-SERVER DELIMITED BY SIZE " "
PRINT-QUEUE DELIMITED BY SIZE
INTO SYS-PARAM.
DISPLAY SYS-PARAM.
CALL "system" USING BY REFERENCE SYS-PARAM.
Resolution:
No null terminator means that the shell will keep parsing memory beyond the end of the passed string, until it hits some arbitrary collection of bytes which generates a syntax error, or hits a signal 11, having run completely off the end of memory.
Here's an example of the correct way to set up a call to system:
01 whole-command-line.
10 command-text pic x(2048).
* Required command line terminator
10 filler pic x low-values. (alternatively value = x"00" can be used)
procedure division.
* STRING statement does not clean out old rubbish
* beyond the end of the STRING result, so...
move spaces to command-text.
STRING "cd $PF/src/EA/SHELL;perl PROCESS_FILES.PL "
DELIMITED BY SIZE
PRTNAME DELIMITED BY SIZE " "
PRINT-SERVER DELIMITED BY SIZE " "
PRINT-QUEUE DELIMITED BY SIZE
INTO command-text.
* Make the call using the command string AND the null terminator.
call 'SYSTEM' using whole-command-line.
Please note also that special characters on the command line, such as parentheses, ampersand, dollar sign, quotation marks, and apostrophes may need to be preceded by the escape character, "\\" to keep the shell from removing them prematurely. For example:
cob -xP pi.cbl -C SETTINGS"COL3"
will fail because the shell will strip off the required quotes before the "cob" command gets to see them. The "cob" command actually gets:
cob -xP pi.cbl -C SETTINGSCOL3
and doesn't know what to make of "SETTINGSCOL3".
Here's the correct way:
cob -xP pi.cbl -C SETTINGS\\"COL3\\"
The shell will remove the escape characters, but not the quotes, so the "cob" command receives:
cob -xP pi.cbl -C SETTINGS"COL3"
which is correct.