Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ basename(1) — HP-UX 8.05

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

expr(1)

sh(1)

basename(1)

NAME

basename, dirname − extract portions of path names

SYNOPSIS

basename string [suffix]
dirname [string]

DESCRIPTION

basename deletes any prefix ending in / and the suffix (if present in string) from string, and prints the result on the standard output. It is normally used inside command substitution marks (`...`) within shell procedures.

dirname delivers all but the last level of the path name in string. If string does not contain a directory component, dirname returns ".", indicating the current working directory. 

EXTERNAL INFLUENCES

Environment Variables

LC_CTYPE determines the interpretation of string and, in the case of basename, suffix as single and/or multi-byte characters. 

If LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable.  If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG.  If any internationalization variable contains an invalid setting, basename and dirname behave as if all internationalization variables are set to "C".  See environ(5).

International Code Set Support

Single- and multi-byte character code sets are supported. 

EXAMPLES

The following shell script, invoked with the argument /usr/src/cmd/cat.c, compiles the named file and moves the output to a file named cat in the current directory:

cc $1
mv a.out `basename $1 .c`

The following example sets the shell variable NAME to /usr/src/cmd:

NAME=`dirname /usr/src/cmd/cat.c`

RETURNS

Both commands return 0 for success.  Both commands return 1 when given an incorrect number of arguments. 

SEE ALSO

expr(1), sh(1). 

STANDARDS CONFORMANCE

basename: SVID2, XPG2, XPG3, proposed POSIX.2 FIPS (June 1990)

dirname: SVID2, XPG2, XPG3, proposed POSIX.2 FIPS (June 1990)

Hewlett-Packard Company  —  HP-UX Release 8.05: June 1991

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026