benhoyt / goawk

A POSIX-compliant AWK interpreter written in Go, with CSV support

Home Page:https://benhoyt.com/writings/goawk/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

-v must interpret escape sequences

ko1nksm opened this issue · comments

Hi, @benhoyt.

-v must interpret escape sequences. I hate this spec of awk, but anyway, reality is what it is. ☹️

$ goawk -v VAR='\t' 'BEGIN{printf VAR}' | hexdump -C
00000000  5c 74                                             |\t|

$ mawk -v VAR='\t' 'BEGIN{printf VAR}' | hexdump -C
00000000  09                                                |.|

$ gawk -v VAR='\t' 'BEGIN{printf VAR}' | hexdump -C
00000000  09                                                |.|

Hi @ko1nksm, thanks for your recent bug reports. This is an interesting one. I'll take a look at these in the next few days.

Out of interest, what are you using GoAWK for? Are you using it as a Go library or via the goawk command line tool?

I am testing if goawk (command line tool) can be used as an implementation of awk that shdotenv uses internally.

If you are interested, you can perform the test by following the steps below.

$ printf "FOO='ABC'" | SHDOTENV_AWK=goawk ./src/shdotenv --no-allexport -e -
FOO='ABC'

# Note: incorrect output
$ printf "FOO='ABC'" | SHDOTENV_AWK=goawk ./src/shdotenv -f jsonl -e -
{ "FOO": "\bABC\b" }

# or run all tests
$ shellspec -e AWK=goawk

Thanks for that. I've fixed this via PR #132 (also for the other var=value form).