在脚本中重定向输入
#!/bin/bash
exec 0< test.sh
count=1
while read line
do
echo "Line #$count: $line"
count=$[ $count + 1 ]
done
运行结果
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
cat test.sh
Fri Jun 16 23:13:05 CST 2023
Fri Jun 16 23:23:53 CST 2023
Fri Jun 16 23:23:53 CST 2023
Mon Jul 10 21:21:35 CST 2023
Mon Jul 10 21:21:35 CST 2023
Mon Jul 17 19:11:41 CST 2023
Mon Jul 17 19:11:41 CST 2023
Mon Jul 17 19:17:22 CST 2023
Mon Jul 17 19:17:22 CST 2023
Mon Jul 17 19:18:31 CST 2023
Mon Jul 17 19:18:31 CST 2023