for_null.sh内容:
1 #!/bin/bash 2 #for null line 3 #version 1.0 by feng 4 5 IFS=$' ' 6 for i in `cat $1` 7 do 8 if [ ${#i} -eq 0 ];then 9 echo "the line is null" 10 else 11 echo "$i" 12 fi 13 done
1 [root@localhost for]# cat a.txt 2 feng 123 3 4 xiao 456 5 6 7 [root@localhost for]# cat for_null.sh
[root@localhost for]# cat -A -n a.txt
1 feng 123$
2 $
3 xiao 456$
4 $
5 ^I^I $
1 [root@localhost for]# sh for_null.sh a.txt 2 feng 123 3 xiao 456 4 5 6 [root@localhost for]#
可以发现,for循环的特点:当以回车作为分隔符时,此处的方式为 for i in "feng 123" 此处多了一个回车分隔符 "xiao 456" " " (引号中为空格) " "(引号中为空格和tab键) 的取值特点。