File: dirname.awk

package info (click to toggle)
runawk 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: awk: 1,127; ansic: 736; sh: 420; makefile: 103
file content (29 lines) | stat: -rw-r--r-- 572 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Written by Aleksey Cheusov <vle@gmx.net>, public domain
#
# This awk module is a part of RunAWK distribution,
#        http://sourceforge.net/projects/runawk
#    
############################################################

# =head2 dirname.awk
#
# =over 2
#
# =item I<dirname (PATH)>
#
# return dirname portion of the PATH
# (the same as I<dirname(3)>)
#
# =back
#
# See example/demo_dirname for the sample of usage
#

function dirname (pathname){
	if (!sub(/\/[^\/]*\/?$/, "", pathname))
		return "."
	else if (pathname != "")
		return pathname
	else
		return "/"
}