20.28 如何向awk脚本中传递外部变量
http://scz.617.cn/unix/201509231030.txt
A: scz 2015-09-23 10:30
有两种办法,一种是单引号,另一种是-v。
#!/bin/bash
nawk="/bin/nawk" CURRENT_SHELL_PID=$(echo $$)
printf "%u\n" "${CURRENT_SHELL_PID}"
nawkcmd='
BEGIN
{
#
# 为了引用外部变量,必须使用单引号,否则不会发生替换
#
current_shell_pid = "'${CURRENT_SHELL_PID}'"
printf( "%u\n", current_shell_pid )
}
'
#!/bin/bash
nawk="/bin/nawk" CURRENT_SHELL_PID=$(echo $$)
printf "%u\n" "${CURRENT_SHELL_PID}"
nawkcmd='
BEGIN
{
printf( "%u\n", current_shell_pid )
}
'