【发布时间】:2014-03-26 02:56:26
【问题描述】:
我有一个 COBOL 程序,它应该通过 shell 脚本运行,并且应该接受此处文档中的值。在此处的文档中,我应该调用一个函数,该函数应该让控件使用退出代码异常退出。
我已经尝试如下,但它不适合我。
这是我的 COBOL 程序:
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".
这是我的 shell 脚本:
#!/bin/bash
funexit ()
{
echo "calling funexit"
exit 1
}
/caplus/pub/test123<<:EOD:
1
g
$(funexit)
Y
:EOD:
输出为:
[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
当从这里调用函数时,COBOL 程序接受值作为“C”,因为在函数:它调用 echo 命令并考虑“调用 funexit”字符串中的第一个字符,而不是退出。
从函数中,我删除了如下的 echo 语句:
#!/bin/bash
funexit ()
{
exit 1
}
/caplus/pub/test123<<:EOD:
1
g
$(funexit)
Y
:EOD:
输出为:
[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.
当从这里调用函数时,COBOL 程序会接受该值作为空格而不是退出。
脚本应该通过一些退出代码异常退出。
【问题讨论】:
-
如果您使用终端而不是heredoc,“退出”的等价物是什么?
-
@choroba .. 如果我理解正确,终端意味着在命令行。如果是这样,在命令行退出将起作用。但我的要求是通过shell脚本调用COBOL程序,通过shell脚本将接受变量传递给它。这只能通过heredoc来实现。所以我应该使用heredoc。使用退出语句没有限制。任何外壳控制中断语句/逻辑都可能用于异常退出进程..
标签: bash shell unix cobol heredoc