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
1.使用for循环 for line in `cat filename` do echo $line done 2.使用for循环 for line in $(cat filename) do echo $line done 3.使用while循环 while read -r line do echo $line done < filename
这工作小半年了发现以前学的那么多流弊技能都不怎么用,倒是shell用的很多,自己已经从shell小菜鸟一步步走过来,已经要变成大菜鸟=.= 经常需要用shell按行读取配置文件,自己在上面踩了很多坑,可依然没长记性,故记录下来.先创建一个测试用例toy.txt; [VasiliShi@ZXXS workplace]$ cat toy.txt this is 1 this is 2 this is 3 使用while读取 使用while读取文件时候需要配合read,利用read读取文件时,每次调用