O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Display Files - kcat

Here is a simple Korn shell version of the Unix cat command. It is only 3-4 times slower than the Unix version (on a 100-line file), because it uses the exec command for the file I/O.

					#!/bin/ksh
					#
					#     kcat - Korn shell version of cat
					#
					# Check usage
					if (($# < 1))
					then
					print "Usage: $0 file ..."
					exit 1
					fi
					# Process each file
					while (($# > 0))
					do
					# Make sure file exists
					if [[ ! -f $1 ]]
					then
					print "$1: non-existent or not accessible"
					else
					# Open file for input
					exec 0<$1
					while read LINE
					do
					# Display output
					print $LINE
					done
					fi
					# Get next file argument
					shift
					done
				

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required