第一种方法:采用单引号加双引号的方式,如'"$i"'
for i in $(<$TMP_FILE); do awk -F "'" '/'"$i"'/{ if($2 ~ /\<'"$i"'\>/) print " ",$2," ",$4," ",$6 }' $UPLOAD_FILE else echo "server $i not in the file." done
第二种方法:变量传递
for i in $(<$TMP_FILE); do awk -F "'" '/'"$i"'/{ if($2 == sername) print " ",$2," ",$4," ",$6 }' sername=$i $UPLOAD_FILE else echo "server $i not in the file." done
转载于:https://blog.51cto.com/zliang90/1322265