Shell Script To Simulate UNIX More Command To Display Only The 15 Lines At A Time

#!/bin/bash
# Write a shell script like a more command. It asks the user name, the 
# name of the file on command prompt and displays only the 15 lines of
# the file at a time.
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
counter=1
echo -n "Enter a file name : "
read file
 
if  [ ! -f $file ]
then
	echo "$file not a file!"
	exit 1
fi
 
# read file line by line
exec 3<&0
while read line
do
       # pause at line no. 15
	if [ $counter -eq 15 ]
	then
		counter=0 # reset counter
		echo " *** Press [Enter] key to continue ..."
		read -u 3 enterKey
	fi
	echo $line
	(( counter++ ))
done < $file
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • stephane Sep 1, 2016 @ 16:24

    can some one help me to write a shell script that simulate the command more thanks

  • supriya Kulkarni Oct 29, 2010 @ 13:31

    please send the c code for the above shell script

  • ghostdog74 Sep 20, 2008 @ 13:01

    you can just do [code]more -15 file[/code]

    • shadyabhi Jan 17, 2010 @ 17:49

      @ghostdog74
      The question is about doing it without using the more command…

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.