original-mawk
original-mawk copied to clipboard
Improper shell quote handling
If the title is unsatisfactory feel free to change it (I was not sure of a proper title nor of the root cause of the bug).
The following awk program does not function correctly (run with mawk -f ./filename.awk
):
function PrintTestBroken(var)
{
"printf '" var "'" | getline result
close("printf '" var "'")
print result
}
function PrintTestWorking(var)
{
cmd = "printf '" var "'"
cmd | getline result
close(cmd)
print result
}
function PrintTestWorkingTwo(var)
{
"printf 'test'" | getline result
close("printf 'test'")
print result
}
BEGIN {
testvar = "test"
PrintTestWorking(testvar)
PrintTestWorkingTwo(testvar)
PrintTestBroken(testvar)
}
It outputs:
test
test
/bin/sh: 1: Syntax error: Unterminated quoted string
test
when it should output:
test
test
test
gawk has the proper output if that helps at all.
thanks (I can reproduce this)
Also I noticed that the following works (notice parentheses):
function PrintTestWorkingThree(var)
{
("printf '" var "'") | getline result
close("printf '" var "'")
print result
}