读文件
script % touch read.sh
script % chmod 755 read.sh
#!/usr/bin/env bashfileName=""
echo input file name:
read fileName # 等待用户输入文件名
COUNT=1while read -r LINE # 读入一行
doecho $COUNT $LINE((COUNT++))
done < $fileName # 读入文件
exit 0
script % ./read.sh
input file name:
food.txt
1 apple
2 grape
3 blackberry
food.txt:
apple
grape
blackberry
写入文件 >
read.sh:
#!/usr/bin/env bashCOUNT=1while read -r LINE # 读入一行
doecho $COUNT $LINE((COUNT++))
done < $1 # 读入文件
exit 0
将读文件的结果写入out.txt:
script % ./read.sh food.txt > out.txt
script % cat out.txt
1 apple
2 grape
3 blackberry