ThomasDickey / original-mawk

bug-reports for mawk (originally on GoogleCode)
http://invisible-island.net/mawk/mawk.html
18 stars 2 forks source link

Improper shell quote handling #55

Open GreenBeard opened 6 years ago

GreenBeard commented 6 years ago

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.

ThomasDickey commented 6 years ago

thanks (I can reproduce this)

GreenBeard commented 6 years ago

Also I noticed that the following works (notice parentheses):

function PrintTestWorkingThree(var)
{
  ("printf '" var "'") | getline result
  close("printf '" var "'")
  print result
}