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
- https://www.oreilly.com/library/view/learning-the-bash/1565923472/ch01s09.html
- https://www.grymoire.com/Unix/Quote.html
- https://blog.fpmurphy.com/2012/04/strong-and-weak-quoting-in-shell-scripts.html
AWK's -v option