1、获取普通外部变量
root@zabbix backup]# i=1
[root@zabbix backup]# awk i=”$i” ‘{print i}’ qlive.collect.sh
awk: cmd. line:1: fatal: cannot open file `{print i}’ for reading (No such file or directory)
正确格式 awk ‘{action}’ 变量=’变量值’
awk ‘{print i}’ i=”$i” qlive.collect.sh
1
2、BEGIN语句中的变量
i=1
awk -v i=”$i” ‘BEGIN{print i}’
1
3.获得环境变量
[chengmo@localhost ~]$ awk ‘BEGIN{for (i in ENVIRON) {print i”=”ENVIRON[i];}}’
AWKPATH=.:/usr/share/awk
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SELINUX_LEVEL_REQUESTED=
SELINUX_ROLE_REQUESTED=
LANG=en_US.UTF-8
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/191433.html