awk: fix 'delete array[var--]' decrementing var twice

function                                             old     new   delta
evaluate                                            3395    3390      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2018-01-07 01:19:08 +01:00
parent 7367a949a6
commit 6f4a785bd1
2 changed files with 50 additions and 23 deletions

View File

@@ -261,6 +261,25 @@ end d
" \
"" ""
prg='
BEGIN{
cnt = 0
a[cnt] = "zeroth"
a[++cnt] = "first"
delete a[cnt--]
print cnt
print "[0]:" a[0]
print "[1]:" a[1]
}'
testing "awk 'delete a[v--]' evaluates v-- once" \
"awk '$prg'" \
"\
0
[0]:zeroth
[1]:
" \
"" ""
testing "awk handles empty ()" \
"awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" ""