長い行を整形する

#!/bin/sh
#nfmt.sh
#nroffを使ったfmt
#-w行の幅を指定する
#-hハイフネーションを有効にする

while getopts "hw:" opt; do
    case $opt in
        h ) hyph=1          ;;
        w ) width="$OPTARG" ;;
    esac
done
shift $(($OPTIND -1))

nroff << EOF
.ll ${width:-72}
.na
.hy ${hyph:-0}
.pl 1
$(cat "$@")
EOF
exit 0
$ cat ragged.txt
So she sat on, with closed eyes, and half believed herself in
Wonderland, though she knew she had but to open them again, and
all would change to dull reality--the grass would be only rustling in the wind, and the pool rippling to the waving of the reeds--the
rattling teacups would change to tinkling sheep- bells, and the
Queen's shrill cries to the voice of the shepherd boy--and the
sneeze 
of the baby, the shriek of the Gryphon, and all thy other queer noises, would change (she knew) 
to the confused clamour of the busy farm-yard--while the lowing of 
the cattle in 
the distance would take the place of the Mock Turtle's heavy sobs.

$ ./nfmt.sh -h -w 50 ragged.txt 
So she sat on, with closed eyes, and half believed
herself in Wonderland, though she knew she had but
to open them again, and all would change to dull
reality--the grass would be only rustling in the
wind, and the pool rippling to the waving of the
reeds--the rattling teacups would change to tin-
kling sheep- bells, and the Queen's shrill cries
to the voice of the shepherd boy--and the sneeze
of the baby, the shriek of the Gryphon, and all
thy other queer noises, would change (she knew) to
the confused clamour of the busy farm-yard--while
the lowing of the cattle in the distance would
take the place of the Mock Turtle's heavy sobs.

$ ./nfmt.sh ragged.txt 
So she sat on, with closed eyes, and half believed herself in
Wonderland, though she knew she had but to open them again, and all
would change to dull reality--the grass would be only rustling in the
wind, and the pool rippling to the waving of the reeds--the rattling
teacups would change to tinkling sheep- bells, and the Queen's shrill
cries to the voice of the shepherd boy--and the sneeze of the baby, the
shriek of the Gryphon, and all thy other queer noises, would change (she
knew) to the confused clamour of the busy farm-yard--while the lowing of
the cattle in the distance would take the place of the Mock Turtle's
heavy sobs.