在下面的代码中,我试图将 shell 变量传递给 awk。但是当我尝试将它作为 a.sh foo_bar 运行时,打印的输出是“foo is not declared”,而当我作为 a.sh bar_bar 运行它时,打印的输出是“foo is declared”。awk 中是否有错误,或者我在这里做错了什么?
我正在使用 gawk-3.0.3。
#!/bin/awk
model=$1
awk ' {
match("'$model'", /foo/)
ismodel=substr("'$model'", RSTART, RLENGTH)
if ( ismodel != foo ) {
print " foo is not declared"
} else {
print " foo is declared"
}
}
' dummy
dummy 是带有单个空行的文件。
谢谢,