[root@localhost cjj]# cat 1.txt 
FillAttachmentc
LoadActLog.sh  
LoadStatiscs.sh 
policyclient
[root@localhost cjj]# 

[root@localhost cjj]# for i in $(cat 1.txt); do echo $i; done
FillAttachmentc
sh
LoadActLog.sh
sh
LoadStatiscs.sh
policyclient
[root@localhost cjj]#  

[root@localhost cjj]# while read line 
> do
> echo $line
> done < 1.txt 
FillAttachmentc
sh LoadActLog.sh
sh LoadStatiscs.sh
policyclient
[root@localhost cjj]# while read line ; do echo $line; done < 1.txt 

[root@localhost cjj]# while read a b
> do
> echo $a
> echo "**************"
> echo $b
> done < 1.txt 
FillAttachmentc
**************


sh
**************
LoadActLog.sh
sh
**************
LoadStatiscs.sh
policyclient
**************


[root@localhost cjj]#


[root@localhost cjj]# read a 
asa sadsdsds
[root@localhost cjj]# echo $a
asa sadsdsds
[root@localhost cjj]#  


[root@localhost ~]# read a b
sas sdsd sdsd
[root@localhost ~]# echo $a
sas
[root@localhost ~]# echo $b
sdsd sdsd

[root@localhost ~]# 


[root@localhost ~]# read a b
sdsdsd
[root@localhost ~]# echo $a
sdsdsd
[root@localhost ~]# echo $b


[root@localhost ~]# 


[root@localhost ~]# read a b
sds sdsd
[root@localhost ~]# echo $a
sds
[root@localhost ~]# echo $b
sdsd
[root@localhost ~]# 

read读入一行,如果只有一个要输入的变量,则不区分空格全部给变量;如果有多个变量,则将空格分隔的变量给相应变量,如果字段少于变量则最后的变量为空,如果字段多于变量则最后的字段全部给最后的变量(即最后的变量没区分空格)




Logo

更多推荐