8.3.1. Write a "more" script
Create the following script with a text editor and save it as
~/staging/bin/more.sh
#!/bin/sh
#
# more.sh - emulates the basic functions of the "more" binary without
# requiring ncurses or termcap libraries.
#
# Assume input is coming from STDIN unless a valid file is given as
# a command-line argument.
if [ -f "$1" ]; then
INPUT="$1"
else
INPUT="/dev/stdin"
fi
#
# Set IFS to newline only. See BASH(1) manpage for details on IFS.
IFS=$'\n'
#
# If terminal dimensions are not already set as shell variables, take
# a guess of 80x25.
if [ "$COLS" = "" ]; then
COLS=80;
fi
if [ "$ROWS" = "" ]; then
ROWS=25;
fi
#
# Initialize line counter variable
ROW_COUNTER=$ROWS
#
# Read the input file one line at a time and display on STDOUT until
# the page fills up. Display "Press <Enter>" message on STDERR and wait
# for keypress from STDERR. Continue until the end of the input file.
# Any input line greater than $COLS characters in length is wrapped and
# counts as multiple lines.
#
while read -n $COLS LINE_BUFFER; do
echo "$LINE_BUFFER"
ROW_COUNTER=$(($ROW_COUNTER - 1))
if [ $ROW_COUNTER -le 1 ]; then
echo "Press <ENTER> for next page or <CTRL>+C to quit.">/dev/stderr
read</dev/stderr
ROW_COUNTER=$ROWS
fi
done<$INPUT
#
# end of more.sh |
Create a symbolic link for more
bash# ln -s more.sh ~/staging/bin/more |