In the following code, I am trying to pass shell varibale to awk. But when I try to run it as a.sh foo_bar, the output is: "foo is not declared", and when I run it as bar.b.sh, the output is "foo declared". Is there an error in awk or am I doing something wrong here?
I am using gawk-3.0.3.
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 is a file with a single empty line.
Thank,
source
share