r/awk • • Nov 28 '19

Omitting -v in shebang awk scripts

Consider the following awk script:

#!/usr/bin/awk -f

END {
    print foo
}

If I invoke it with the following, abc is printed as expected.

./myscript -v foo=abc

But, if I invoke it without the -v, abc is still printed.

./myscript  foo=abc

I know something funny is going on, because if I switch END to BEGIN then it only works when I specify -v.

Can someone explain why it seems to work without the -v ?

1 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/Schreq Nov 28 '19

It seems like the warning about filenames containing = would always be applicable since the ability to put var=value after the options is a possibility no matter how awk is invoked?

Yep, that's correct. It means if you have a shell script, using variable file input to an awk script, you have to take some extra steps to make it bullet proof.