(管道)写入子shell
随便写一个文件作为第二个文件
cat demo
aaa
bbb
ccc
-----------------------------------------------------------------------------
源码: cat test
if (( $# < 1 )) /*判定输入值或文件是否为空*/
thenecho "Usage: $0 filename " >&2
exit 1
fi
count=1
cat $1 | while read line /*显示第2个文件并读入管道*/
do
((count == 1)) && echo "Processing file $1..." > /dev/tty /*第一行内容显示在命令行*/
echo -e "$count\t$line" /*修改---输出管道行值*/
let count+=1
done > tmp$$ /*将输出的列表存入临时文件tmp$$*/
mv tmp$$ $1 /*将临时文件temp$$修改名称到第二个文件$1*/
------------------------------------执行结果--------------------------------------------------
[root@luozhonghua Ex_14.32-14.55]# sh numberit memo
Processing file memo...
tmp5303
[root@luozhonghua Ex_14.32-14.55]# cat memo
1 aaa
2 bbb
3 ccc
地瓜园