Awk uses the following methods to reference external variables to call variables: www.2cto.com 1. awk '{print a, B} 'a = 111 B = 222 yourfile note that the variable location must be before the file name, otherwise it cannot be called. for example: awk '{print a, B} 'a = 111 file1 B = 222 file2file1 cannot call B = 222. also, variable cannot be called in BEGIN. it can be solved using the second method described later. www.2cto.com 2. awk-v a = 111-v B = 222 '{print a, B}' yourfile Note: Add a-v for each variable for transmission. 3. awk '{print "'" $ LOGNAME "'}' yourfile: to call environment variable, use the preceding method: (I add a space to make It is easy to understand) "'" $ LOGNAME "'" instance :#! /Bin/bash # This function lists the names of files whose names start with a date and are earlier than a certain date. It can be used to delete filtering curdate = 20110715 Filename = 'LS-l | awk-v cdate = $ curdate 'nr! = 1 & $8 <cdate {print $8} ''echo $ Filename