- 论坛徽章:
- 17
|
硬件:Pentium D CPU 3.00GHz
软件:redhat as4u4 系统
1.为什末t3.sh的执行结果中没有127.0.0.1呢,使被awk过滤没了?(hosts,t1.sh,t2.sh,t3.sh在相同目录下)
2.t3.sh中 ADDR=`awk '{print $1}'`的awk的是针对那个文件过滤得呢?
###########################
hosts内容
cat hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
#::1 localhost6.localdomain6 localhost6
192.168.1.1 gateway.lighten.com gateway
192.168.1.2 linux
1.1.1.1 xp1
2.2.2.2 xp2
###########################
t1.sh 内容
cat t1.sh
#!/bin/sh
cat hosts | grep -v '^#' | awk '{print $1}'
./t1.sh执行结果
[root@gateway ~]# ./t1.sh
127.0.0.1
192.168.1.1
192.168.1.2
1.1.1.1
2.2.2.2
###########################
t2.sh内容
cat t2.sh
#!/bin/sh
cat hosts | grep -v '^#' | while read LINE ; do
echo $LINE
done
t2.sh执行结果
127.0.0.1 localhost.localdomain localhost
192.168.1.1 gateway.lighten.com gateway
192.168.1.2 linux
1.1.1.1 xp1
2.2.2.2 xp2
###########################
t3.sh内容
cat t3.sh
#!/bin/sh
cat hosts | grep -v '^#' | while read LINE ; do
ADDR=`awk '{print $1}'`
for M in $ADDR ; do
echo $M
done
done
t3.sh执行结果
192.168.1.1
192.168.1.2
1.1.1.1
2.2.2.2
########################### |
|