有时,我们需要列出脚本的行号,以使其看起来清晰明了。
复制代码代码如下:
#!/bin/sh
# filename: line_file.sh function list_num () { FILENAME=$1 if [ $# -ne 1 ];then echo "USEAGE: list_num arg ,arg is a chanchu file name" return 1 fi LOOP=1 while read LINE do echo "$LOOP: $LINE" LOOP=`expr $LOOP + 1` done <$FILENAME }
[root@localhost ~]# ./line_file.sh |