got the following script from a unix website:
how do i run this script?
can i change the beginning line to:
to:
how do i run this script?
Code:
#! /usr/bin/ksh
#
# scroller --- display text, but sleep every few lines.
#
#
# scroller will copy 5 lines from standard input to the
# local terminal and then sleep for one second.
#
# You can override the 5 lines with a "-l n" option.
# And you use a "-s n" to override the sleep time.
#
# You can type your interrupt character (often control c)
# to get a menu that will let you adjust these values.
#
# You can use -m to go straight to the menu at startup
#
# You can specify filenames or scroller can just read from
# standard in.
#
USAGE="usage: scroller [-s n] [-l n] [-m] [filename1] [filename2] ..."
#
# initialize variables
#
# Set reasonable initial values here. TASK controls the main
# loop as described below. snooze is the number of seconds for
# the sleep. lpp (lines per page) is the number of lines to
# dispaly before sleeping. lines will repeatedly cycle from 0
# to npp as the program runs. totallines is a count of lines
# processed so far. And we turn off IFS so the reads work with
# data that has leading white space.
TASK=2
snooze=1
lpp=5
lines=0
totallines=0
IFS=""
#
# Now Process the command line
#
error=0
while getopts :s:l:m o ; do
case $o in
s) if [[ $OPTARG -gt 0 && $OPTARG -lt 100 ]] ; then
snooze=$OPTARG
else
print $OPTARG is illegal
error=1
fi
;;
l) if [[ $OPTARG -gt 0 && $OPTARG -lt 100 ]] ; then
lpp=$OPTARG
else
print $OPTARG is illegal
error=1
fi
;;
m) TASK=2
;;
?) print error argument $OPTARG is illegal
error=1
;;
esac
done
shift OPTIND-1
if ((error)) ; then
print $USAGE
TASK=0
fi
#
# Open first file or indicate that we are using stdin
#
if (($# >= 1)) ; then
input=$1
exec < $input
shift
else
input="(standard input)"
fi
#
# Major loop. TASK can be 0 or 1 or 2. If TASK is set we
# loop doing either task 1 or task 2. Either task can switch
# to the other. And both tasks can abort by setting TASK=0.
# But control c will switch to task 1.
#
trap interrupt=1 2
interrupt=0
while ((TASK)) ; do
if ((interrupt)) ; then
interrupt=0
TASK=1
fi
case $TASK in
#
# Task 1 --- display service menu
#
1) print
print '=====[[ scroller service menu ]]====='
print
print " $totallines lines processed so far from $input"
print " sleep seconds = $snooze"
print " lines per page = $lpp"
print
print ' 1) list the text'
print ' 2) set lines per page'
print ' 3) set sleep seconds'
print ' 4) abort'
print
print -n "[Enter Selection]====>>"
read < /dev/tty
case $REPLY in
1) TASK=2
;;
2) print lines per page is currently $lpp
print -n enter new value --
read val < /dev/tty
if [[ $val -gt 0 && $val -lt 100 ]] ; then
lpp=$val
else
print $val is illegal
fi
;;
3) print sleep seconds is currently $snooze
print -n enter new value --
read val < /dev/tty
if [[ $val -gt 0 && $val -lt 100 ]] ; then
snooze=$val
else
print $val is illegal
fi
;;
4) TASK=0
;;
*) print illegal response
print REPLY = $REPLY
;;
esac
;;
#
# Task 2 --- copy lines from stdin to stdout
#
# Read a line, increment counts, sleep if it's time
#
2) if read line ; then
print -r -- "$line"
((totallines=totallines+1))
((lines=lines+1))
if ((lines >= lpp)) ; then
lines=0
sleep $snooze
fi
else
#
# No more input. Open a new file or give up.
#
if [[ $# -ge 1 ]] ; then
input=$1
exec < $input
shift
else
TASK=0
fi
fi
;;
#
# Task * --- can't happen
#
*) print -u2 $0: impossible error TASK = $TASK
TASK=0
;;
esac
done
((totallines)) && print "$totallines" total lines processed
exit 0
how do i run this script?
can i change the beginning line to:
Code:
#! /usr/bin/ksh
to:
Code:
#!/usr/bin/bash
how do i run this script?