#!/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 via:

Category List of Unix and Linux commands
Disk space analyzers df duf ncdu pydf
File Management cat cp mkdir tree
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilities bat exa
Network Utilities NetHogs 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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searching ag grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • 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…

  • supriya Kulkarni Oct 29, 2010 @ 13:31

    please send the c code for the above shell script

  • stephane Sep 1, 2016 @ 16:24

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum