jcampbell05 / volcano

A programming language which compiles to shell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use strong quotes and -v option for AWK

DLopezJr opened this issue · comments

Would suggest to produce output that uses AWK to have strong quotes (') and the -v option for passing variables.


AWK uses weak quote (") itself for managing strings. In my experience, writing shell variables directly inside of AWK code becomes an escaping mess due to the shared used of $ for two different meanings. ($ in shell is calling variables, $ in AWK is calling fields)

The easier way for me has been to use -v option (from the POSIX spec) that allows you pass sh variables while using strong quotes on AWK.

In this script of mine you can see an example in use: awk -F. -v app="$1" '(tolower($0) ~ tolower(app))'

As you can see, no escaping is needed when using the -v option.


REFERENCES

Strong Quotes

AWK's -v option