分类: LINUX
2018-03-17 13:49:33
#!/bin/bash
_FILE_NAME_=$1
function read_file_1()
{
while read _LINE_
do
printf "${_LINE_}\n"
done < ${_FILE_NAME_}
}
function read_file_2()
{
cat ${_FILE_NAME_} | while read _LINE_
do
printf "${_LINE_}\n"
done
}
printf "read_file_1:\n"
read_file_1
printf "#################\n"
printf "read_file_2:\n"
read_file_2
执行结果:
tay@tay:/mnt/hgfs/hzs/shell$ cat a.txt
number name birthday gender
1234 zhangsan 19911212 man
4567 lisi 20011212 woman
5214 wangmazi 20411012 man
4574 jia 20320101 woman
1456 yan 20000101 woman
tay@tay:/mnt/hgfs/hzs/shell$ ./read_file.sh a.txt
read_file_1:
number name birthday gender
1234 zhangsan 19911212 man
4567 lisi 20011212 woman
5214 wangmazi 20411012 man
4574 jia 20320101 woman
1456 yan 20000101 woman
#################
read_file_2:
number name birthday gender
1234 zhangsan 19911212 man
4567 lisi 20011212 woman
5214 wangmazi 20411012 man
4574 jia 20320101 woman
1456 yan 20000101 woman
tay@tay:/mnt/hgfs/hzs/shell$