Shell脚本,执行解释速度快.代码简单易于理解.在shell代码编写过程中,经常会用到读取文件内容. 写法一: ---------------------------------------------------------------------------- #!/bin/bash while read line do echo $line done < file(待读取的文件) ------------------------------------------
写法一: #!/bin/bash while read line do echo $line done < file(待读取的文件) 写法二: #!/bin/bash cat file(待读取的文件) | while read line do echo $line done 写法三: for line in `cat file(待读取的文件)` do echo $line done 说明:for逐行读和while逐行读是有区别的,如: $ cat file aaaa bbbb cccc dddd
shell脚本实现读取一个文件中的某一列,并进行循环处理 1) for循环 #!bin/bash if [ ! -f "userlist.txt" ]; then echo "userlist.txt 不存在!" fi for userid in `(cat userlist.txt)` do a=$userid echo $a done #!bin/bash if [ ! -f userlist.txt ]; then echo "userlist.tx
写法一: ---------------------------------------------------------------------------- #!/bin/bash while read line do echo $line done < filename(待读取的文件) ---------------------------------------------------------------------------- 写法二: --------------------