Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Awk introduces external variable method

Shulou Source: shulou.com Published: 2022-06-03 06:44:27 11月23日 Update

1. Get ordinary external variables

Root@zabbix backup] # iTun1

[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)

Correctly formatted awk'{action} 'variable =' variable value'

Awk'{print I}'I = "$I" qlive.collect.sh

one

2. Variables in BEGIN statement

I, 1

Awk-v I = "$I" 'BEGIN {print I}'

one

3. Get environment variables

[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

Tags: Variables normal format environment statements values methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple OPPO Reno NVidia vpn