shell-002 while

0

#!/bin/bash
i=1
while ((i<20))
do
        ((i=i+1))
done
echo $i

1. baby_rocker.sh

baby_rocker.sh
#!/bin/bash
while [ 1=1 ]
do
	 eject
	 eject -t 
done

2. repeat.sh

#!/bin/bash
declare -i i=0
declare -i MAX=1000

while ((i<MAX))
do
        cat source.txt >> input.txt
        let i++
done

echo "i=$i"
exit 0

3. 读文件,一次读一行,并打印

#!/bin/bash
while read line
do
        echo $line
done < input.txt


4. 循环读/etc/passwd,并分析出以:隔离的字段

#!/bin/bash
IFS=':'
cat /etc/passwd | {
while read f1 f2 f3 f4 f5 f6 f7
do
        echo "username: $f1, login shell: $f7"
done
}

5

#!/bin/bash

foo=1

while [ "$foo" -le 20 ]; do
    echo "once again"
    foo=$(($foo+1))
done

echo "foo=$foo" 

exit 0

6 simplest

#!/bin/bash
while [ 1 = 1 ]
do
    echo "haha"
    echo "hehe"
done



你可能感兴趣的:(shell,login)