本文介绍了开关/箱不工作的awk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写在RedHat Linux上一个简单的awk,却发现交换机/案例并不为我工作。我搜索的网页,但没有找到一个解决方案。以下是我的code:
BEGIN {
富= 1;
开关(富){
案例3:
打印×;
打破;
案例2:
打印Y;
打破;
情况1:
打印Z;
打破;
默认:
打印默认;
}
}
我运行awk的是GNU awk的3.1.5。我得到了以下错误:
awk: test.awk:3: switch (foo) {
awk: test.awk:3: ^ syntax error
awk: test.awk:5: case 3:
awk: test.awk:5: ^ syntax error
awk: test.awk:8: case 2:
awk: test.awk:8: ^ syntax error
awk: test.awk:11: case 1:
awk: test.awk:11: ^ syntax error
awk: test.awk:14: default:
awk: test.awk:14: ^ syntax error
can anybody please help me out? thank you!
解决方案
The GAWK manual says:
Which version of gawk
are you using? Was it compiled with the --enable-switch
option?
If you can't tell whether gawk
was compiled with --enable-switch
and you are getting syntax errors, it is reasonable to infer that it is not. I'm using gawk 3.1.8
compiled with the default configuration and get pretty much exactly the errors you are seeing on your script. Given that, it is highly unlikely that your version is compiled with the necessary configuration option. It isn't hard to recompile gawk
with the option if you want to.
这篇关于开关/箱不工作的awk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!