[[email protected] ~]# vi readFile.sh
[[email protected] ~]# ll
总用量 286460
-rw-r--r-- 1 root root 0 11月 22 13:54 a
-rw-r--r-- 1 root root 0 11月 22 13:54 ab
-rw-r--r-- 1 root root 0 11月 22 13:54 abc
-rwxr-xr-x 1 root root 251 12月 3 17:36 addlinuxuser.sh
-rw-r--r-- 1 root root 135 11月 27 17:34 awk.txt
-rwxr-xr-x 1 root root 193 12月 5 15:39 findMaxFile.sh
-rw-r--r-- 1 root root 111 11月 22 15:50 grep.txt
-rw-r--r-- 1 root root 511 11月 24 00:11 inittab
-rw-r--r-- 1 root root 138090286 11月 28 18:02 jdk-7u80-linux-x64.rpm
-rw-r--r-- 1 root root 153530841 11月 28 18:02 jdk-7u80-linux-x64.tar.gz
-rw-r--r-- 1 root root 2347 11月 27 16:49 passwd
-rwxr-xr-x 1 root root 1833 11月 22 12:28 profile
-rw-r--r-- 1 root root 12 12月 5 15:50 readFile.sh
-rw-r--r-- 1 root root 53 12月 3 09:23 sh01.sh
-rw-r--r-- 1 root root 26 12月 3 14:17 sh02.sh
-rw-r--r-- 1 root root 106 12月 3 14:21 sh03.sh
drwxr-xr-x 2 root root 170 12月 2 22:40 shell
-rw-r--r-- 1 root root 38 11月 24 00:09 sort.txt
drwxr-xr-x 12 50469 users 4096 11月 28 18:38 tengine-2.1.0
-rw-r--r-- 1 root root 1653240 11月 28 18:02 tengine-2.1.0.tar.gz
[[email protected] ~]# vi test.txt
[[email protected] ~]# cat test.txt
a 1
b 2
c 3
[[email protected] ~]# cat readFile.sh
#!/bin/bash
num=0
for i in `cat test.txt`; do
echo $i
((num++))
done
echo num:$num
[[email protected] ~]# chmod +x readFile.sh
[[email protected] ~]# ./readFile.sh
a
1
b
2
c
3
num:6
[[email protected] ~]# vi readFile.sh
[[email protected] ~]# cat readFile.sh
#!/bin/bash
num=0
oldIFS=$IFS
IFS=$'\n'
for i in `cat test.txt`; do
echo $i
((num++))
done
echo num:$num
IFS=$oldIFS
[[email protected] ~]# ./readFile.sh
a 1
b 2
c 3
num:3
[[email protected] ~]# vi readFile.sh
[[email protected] ~]# cat readFile.sh
#!/bin/bash
num=0
oldIFS=$IFS
IFS=$'\n'
for i in `cat test.txt`; do
echo $i
((num++))
done
echo num:$num
IFS=$oldIFS
echo "----------------------"
num=0
lines=`cat test.txt | wc -l`
for ((i=1;i<=lines;i++));do
line=`head -$i test.txt | tail -l`
echo $line
((num++))
done
echo num:$num
[[email protected] ~]# ./readFile.sh
a 1
b 2
c 3
num:3
----------------------
a 1
a 1 b 2
a 1 b 2 c 3
num:3
[[email protected] ~]# vi readFile.sh
[[email protected] ~]# cat readFile.sh
#!/bin/bash
num=0
oldIFS=$IFS
IFS=$'\n'
for i in `cat test.txt`; do
echo $i
((num++))
done
echo num:$num
IFS=$oldIFS
echo "----------------------"
num=0
lines=`cat test.txt | wc -l`
for ((i=1;i<=lines;i++));do
line=`head -$i test.txt | tail -l`
echo $line
((num++))
done
echo num:$num
echo "------------------------------"
num=0
while read line; do
echo $line
((num++))
done < test.txt
echo num:$num
[[email protected] ~]# ./readFile.sh
a 1
b 2
c 3
num:3
----------------------
a 1
a 1 b 2
a 1 b 2 c 3
num:3
------------------------------
a 1
b 2
c 3
num:3
[[email protected] ~]# vi readFile.sh
[[email protected] ~]# cat readFile.sh
#!/bin/bash
num=0
oldIFS=$IFS
IFS=$'\n'
for i in `cat test.txt`; do
echo $i
((num++))
done
echo num:$num
IFS=$oldIFS
echo "----------------------"
num=0
lines=`cat test.txt | wc -l`
for ((i=1;i<=lines;i++));do
line=`head -$i test.txt | tail -l`
echo $line
((num++))
done
echo num:$num
echo "------------------------------"
num=0
while read line; do
echo $line
((num++))
done < test.txt
echo num:$num
echo "------------------------------------------"
num=0
cat test.txt | while read line; do
echo $line
((num++))
done;echo num:$num
[[email protected] ~]# ./readFile.sh
a 1
b 2
c 3
num:3
----------------------
a 1
a 1 b 2
a 1 b 2 c 3
num:3
------------------------------
a 1
b 2
c 3
num:3
------------------------------------------
a 1
b 2
c 3
num:0
[[email protected] ~]# vi readFile.sh
[[email protected] ~]# cat readFile.sh
#!/bin/bash
num=0
oldIFS=$IFS
IFS=$'\n'
for i in `cat test.txt`; do
echo $i
((num++))
done
echo num:$num
IFS=$oldIFS
echo "----------------------"
num=0
lines=`cat test.txt | wc -l`
for ((i=1;i<=lines;i++));do
line=`head -$i test.txt | tail -l`
echo $line
((num++))
done
echo num:$num
echo "------------------------------"
num=0
while read line; do
echo $line
((num++))
done < test.txt
echo num:$num
echo "------------------------------------------"
num=0
cat test.txt | (while read line; do
echo $line
((num++))
done;echo num:$num)
[[email protected] ~]# ./readFile.sh
a 1
b 2
c 3
num:3
----------------------
a 1
a 1 b 2
a 1 b 2 c 3
num:3
------------------------------
a 1
b 2
c 3
num:3
------------------------------------------
a 1
b 2
c 3
num:3
[[email protected] ~]# vi readFile.sh
[[email protected] ~]# cat readFile.sh
#!/bin/bash
num=0
oldIFS=$IFS
IFS=$'\n'
for i in `cat test.txt`; do
echo $i
((num++))
done
echo num:$num
IFS=$oldIFS
echo "----------------------"
num=0
lines=`cat test.txt | wc -l`
for ((i=1;i<=lines;i++));do
line=`head -$i test.txt | tail -l`
echo $line
((num++))
done
echo num:$num
echo "------------------------------"
num=0
while read line; do
echo $line
((num++))
done < test.txt
echo num:$num
echo "------------------------------------------"
num=0
cat test.txt | {while read line; do
echo $line
((num++))
done;echo num:$num;}
[[email protected] ~]# vi argsSh.sh
[[email protected] ~]# . argsSh.sh abcdef
abcdef
abcdef
abcdef
------------------
abcdef
------------------------
abcdef
[[email protected] ~]# . argsSh.sh a b c d e f
a
b
a b c d e f
a b c d e f
------------------
a b c d e f
------------------------
a
b
c
d
e
f