一行Shell代碼逐行讀取文件

#!/bin/bash

printf "*************************************\n"
echo " cat file while read line"
cat one.log |while read line
do
	echo $line;
done

printf "*************************************\n"
echo "while read line <file"
while read line
do
	echo $line;
done <one.log

printf "*************************************\n"
echo "for line in cat test.txt"
SAVEIFS=$IFS
IFS=$(echo -en "\n")
for line in $(cat test.txt)
do
	echo $line;
done
IFS=$SAVEIFS

前二種方法能夠分別簡化成一行簡短的代碼shell

cat one.log|while read line;do echo $line;done

while read line; do echo $line; done<one.log
相關文章
相關標籤/搜索