Tell me, please, why awk does not transmit an external variable to the template. Sample script:

#/bin/sh PROTO="tcp" LINES=(`sudo /sbin/iptables --numeric --line-numbers --list INPUT | awk -v prt=$PROTO '/prt/ {print $1}'`) echo ${LINES[@]} 

Conclusion: an empty array.

Closed due to the fact that off-topic participants Wiktor Stribiżew , AK , Dmitry Kozlov , user192664, Let's say Pie 10 Nov '18 at 10:39 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Wiktor Stribiżew, AK, Dmitry Kozlov, Community Spirit, Let's say Pie
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Error in specifying a template, valid line:

     LINES=(`sudo /sbin/iptables --numeric --line-numbers --list INPUT | awk -v prt=$PROTO '$0 ~ prt {print $1}'`)