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

Dirname - kdirname

Here is the Korn shell version of the Unix dirname command. It returns a pathname minus the last directory. As in kbasename, the substring feature does all the work.

					#!/bin/ksh
					#
					#     kdirname - Korn shell dirname
					#
					# Check arguments
					if (($# == 0 || $# > 1))
					then
					print "Usage: $0 string"
					exit 1
					fi
					# Get the dirname
					print ${1%/*}
				

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