I have a COBOL program which should be run thru shell script and should accept the values from the here document. in the here document, i should call a function that should let control to be exit abnormally with exit code.
I have tried as below but it is not working for me.
This is my COBOL program:
01 WW-ANS PIC X value space.
IRS-200.
display "ARE THE ABOVE ANSWERS CORRECT? Y/N/E".
Accept ws-ans.
display "entered value is " ws-ans "<".
IF WW-ANS = "E" or "e"
PERFORM STOP-RUN-CA.
IF WW-ANS NOT = "Y" AND "N" AND "E"
and "y" and "n" and "e"
PERFORM DISPLAY-01 THRU DISPLAY-01-EXIT
GO TO IRS-200.
IF WW-ANS = "Y" or "y"
display "Program executed successfully"
PERFORM STOP-RUN-CA.
ELSE
GO TO IRS-200.
DISPLAY-01.
DISPLAY "value is >" WW-ANS "<".
DISPLAY "INVALID RESPONSE".
This is my shell script:
#!/bin/bash
funexit ()
{
echo "calling funexit"
exit 1
}
/caplus/pub/test123<<:EOD:
1
g
$(funexit)
Y
:EOD:
Output is:
[Linux Dev:adminusr ~]$ ./test123.sh
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is 1<
value is >1<
INVALID RESPONSE
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is g<
value is >G<
INVALID RESPONSE
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is c<
value is >C<
INVALID RESPONSE
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is Y<
Program executed successfully
When ever function gets called from here document the COBOL program accept the value as "C", since at function: it invoke the echo command and considering the first character from the "calling funexit" string, instead of getting exit.
From the function, I have removed echo statement like below:
#!/bin/bash
funexit ()
{
exit 1
}
/caplus/pub/test123<<:EOD:
1
g
$(funexit)
Y
:EOD:
Output is:
[Linux Dev:adminusr ~]$ ./test123.sh
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is 1<
value is >1<
INVALID RESPONSE
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is g<
value is >G<
INVALID RESPONSE
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is <
value is > <
INVALID RESPONSE
ARE THE ABOVE ANSWERS CORRECT? Y/N/E
entered value is Y<
Program executed successfully.
When ever function gets called from here document the COBOL program accept the value as spaces instead of getting exit.
The script should get exit abnormally with some exit code.