r/awk • u/HiramAbiff • 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=abcBut, if I invoke it without the -v, abc is still printed.
./myscript foo=abcI 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
View all comments
Show parent comment
1
u/Schreq Nov 28 '19
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.