while 循环
[b]1、基本用法:[/b]
[b]2、循环读入一个文件。[/b]
方式1:
方式2:
[b]3、while 循环输出内容到一个文件。[/b]
4、命令行执行for
[b]1、基本用法:[/b]
#!/bin/bash
source /etc/profile
while read dataline
do
echo "$dataline"
done
[b]2、循环读入一个文件。[/b]
方式1:
#!/bin/bash
source /etc/profile
cat $*|
while read dataline
do
echo "$dataline"
done
方式2:
#!/bin/bash
source /etc/profile
filename=$1
if [ ! -r "$filename" ];then
echo "can not read $filename"
exit 1
fi
while read dataline
do
echo "$dataline"
done < $filename
[b]3、while 循环输出内容到一个文件。[/b]
#!/bin/bash
source /etc/profile
filename=$1
if [ ! -r "$filename" ];then
echo "can not read $filename"
exit 1
fi
while read dataline
do
echo "$dataline"
done < $filename >output.data
4、命令行执行for
for i in `cat num2.txt` ;do echo $i; done |awk 'BEGIN {a=0} {a+=$1} END {print a}'