テキストを1行ずつ読み込む
#!/bin/sh #linenum.sh if [ $# -ne 1 ]; then echo "Usage: linenum.sh filename" exit 1 fi IFS=' ' ln=0 #標準入力から1行ずつ読み込み、行番号と共に表示 while read -r line; do ln=`expr $ln + 1` printf '%3d %s\n' "$ln" "$line" done < "$1"
$ ./linenum.sh arith.sh 1 #!/bin/sh 2 #arith.sh 3 4 x=5 5 y=9 6 z=13 7 8 a=`expr $x \* $y` 9 b=`expr \( $y + $z \) / $x` 10 11 echo "$a" 12 echo "$b"