while [ $i -lt num ] while true while read a b c; do command done < filename cat filename | while read a b c
#/bin/bash ## author: yangbk ## site: www.361way.com ## mail: itybku@139.com ## desc: test loop for in and while df -hl|awk 'int($5) >30 ' > testfile result=`df -hl|awk 'int($5) >30 '` echo '******************* for testing *****************' for i in $result;do echo $i done echo '******************* while echo test *************' echo $result | while read line do echo $line done echo '****************** while testing ****************' df -hl|awk 'int($5) >30 '|while read line do echo $IP `hostname` $line done echo '****************** while read file **************' while read line do echo $IP `hostname` $line done < testfile
# sh forwhile.sh ******************* for testing ***************** /dev/sda3 9.5G 5.7G 3.4G 64% / /dev/sda2 39G 19G 18G 52% /home /dev/sda6 9.5G 7.1G 2.0G 78% /usr ******************* while echo test ************* /dev/sda3 9.5G 5.7G 3.4G 64% / /dev/sda2 39G 19G 18G 52% /home /dev/sda6 9.5G 7.1G 2.0G 78% /usr ****************** while testing **************** localhost /dev/sda3 9.5G 5.7G 3.4G 64% / localhost /dev/sda2 39G 19G 18G 52% /home localhost /dev/sda6 9.5G 7.1G 2.0G 78% /usr ****************** while read file ************** localhost /dev/sda3 9.5G 5.7G 3.4G 64% / localhost /dev/sda2 39G 19G 18G 52% /home localhost /dev/sda6 9.5G 7.1G 2.0G 78% /usr
#!/bin/bash
## author: yangbk
## site: www.361way.com
## mail: itybku@139.com
## desc: test wait and ssh when use for in and while
# while loop
echo -en "\t";date
cat abc.txt|while read user ip
do
{
ssh -o ConnectTimeout=10 $user@$ip "hostname" < /dev/null
sleep 10s
} &
done
wait
echo "This is while loop."
echo -en "\t";date
sleep 10s
echo -e "\n"
# for loop
echo -en "\t";date
for line in `cat abc.txt|sed -e 's/ /--/g'`
do
{
user=`echo $line|awk -F '--' '{print $1}'`
ip=`echo $line|awk -F '--' '{print $2}'`
ssh -oConnectTimeout=10 $user@$ip "hostname"
sleep 10s
} &
done
wait
echo "This is for loop."
echo -en "\t";date
$ cat file aaaa bbbb fff ggg cccc dddd $ cat file | while read line; do echo $line; done aaaa bbbb fff ggg cccc dddd $ for line in $(<file); do echo $line; done aaaa bbbb fff ggg cccc dddd
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有