- # Use the debian sensible-pager wrapper to pick the pager
- # user has requested via their $PAGER environment variable
- if [ -x "/usr/bin/sensible-pager" ]; then
- /usr/bin/sensible-pager "$PAGEFILE"
- elif [ -x "$PAGER" ]; then
- # That failed, try to load the preferred editor, starting
- # with their PAGER variable
- $PAGER "$PAGEFILE"
- # If that fails, check for less
- elif [ -x /usr/bin/less ]; then
- /usr/bin/less -f "$PAGEFILE"
- # more should be on all UNIX systems
- elif [ -x /bin/more ]; then
- /bin/more "$PAGEFILE"
+ local NUM_LINES=$(wc -l < "$PAGEFILE")
+
+ # Is the text long enough to need a pager?
+ if [ "$NUM_LINES" -ge $LINES ]; then
+ # Yes!
+ # Use the debian sensible-pager wrapper to pick the pager user
+ # has requested via their $PAGER environment variable
+ if [ -x "/usr/bin/sensible-pager" ]; then
+ /usr/bin/sensible-pager "$PAGEFILE"
+ elif [ -x "$PAGER" ]; then
+ # That failed, try to load the preferred pager, starting
+ # with their PAGER variable
+ $PAGER "$PAGEFILE"
+ # If that fails, check for less
+ elif [ -x /usr/bin/less ]; then
+ /usr/bin/less -f "$PAGEFILE"
+ # more should be on all UNIX systems
+ elif [ -x /bin/more ]; then
+ /bin/more "$PAGEFILE"
+ else
+ # No bananas, just cat the thing
+ cat "$PAGEFILE" >&2
+ fi