在bash脚本中使用gawk时遇到了一个非常奇怪的问题.
在这个脚本中,我使用一个函数来做一些文本处理.即使是非常简单的gawk命令也会返回错误134
#!/bin/bash
testFunc()
{
log "Before gawk: $?"
gawk '{print}' file
log "After gawk: $?"
}
Run Code Online (Sandbox Code Playgroud)
如果我手动运行控制台这个脚本,它会很好地工作,$?将始终为0,这意味着成功,但如果我用这个脚本是Linux的等启动脚本/ rc.d中/ 3的水平,执行GAWK之后,$?是总是134,我不知道134的含义是什么.
如果我更换gawk '{print}' file到gawk --version,结果是正常,$?是0.
PMD报告"正在对捕获的异常执行检查实例.为此异常类型创建单独的catch子句." 以下代码.
String parameter;
try {
...
} catch (Exception e) {
logFailure(e, parameter);
if (e instanceof X) {
throw new A(e);
} else if (e instanceof Y
|| e instanceof Z) {
throw new B(e);
}
throw new InternalServerErrorException(e);
}
Run Code Online (Sandbox Code Playgroud)
如果我将上面的代码改为下面,有3个重复的logFailure(e),有没有更好的方法来消除这种PMD违规?
String parameter;
try {
...
} catch (X e) {
logFailure(e, parameter);
throw new A(e);
} catch (Y e) {
logFailure(e);
throw new B(e);
} catch (Z e) {
logFailure(e);
throw new B(e);
} catch (exception e) { …Run Code Online (Sandbox Code Playgroud)