Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ basename(1) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought



BASENAME, DIRNAME(1,C)      AIX Commands Reference       BASENAME, DIRNAME(1,C)



-------------------------------------------------------------------------------
basename, dirname



PURPOSE

Returns the basename of a string parameter.

SYNTAX


                     +----------+
basename -- string --|          |---|
                     +- suffix -+

dirname -- path --|


DESCRIPTION

The basename command reads the string specified on the command line, deletes
any prefix that ends with a "/" (slash), as well as any specified suffix, if it
is present, and writes the remaining base file name to standard output.  A
basename of "/" is null and is considered an error.

The dirname command writes to standard output all except the last part of the
specified path name (all but the last "/" and the part following it).

The basename and dirname commands are generally used inside command
substitutions within a shell procedure to specify an output file name that is
some variation of a specified input file name.  For more information, see
"Command Substitution."

EXAMPLES

  1. To display the base name of a shell variable:

      basename  $WORKFILE

    This command displays the base name of the value assigned to the shell
    variable "WORKFILE".  If "WORKFILE" is set to "/u/tom/program.c", then
    "program.c" is displayed.

  2. To construct a file name that is the same as another file name, except for
    its suffix:

      OFILE=`basename $1 .c`.o

    This command assigns to "OFILE" the value of the first positional parameter
    ("$1"), but with its ".c" suffix changed to a ".o" suffix.  If the "$1"
    parameter is "/u/tom/program.c", "OFILE" becomes "program.o".  Because



Processed November 8, 1990  BASENAME, DIRNAME(1,C)                            1





BASENAME, DIRNAME(1,C)      AIX Commands Reference       BASENAME, DIRNAME(1,C)



    "program.o" is only a base file name, it identifies a file in the current
    directory.  The `` (grave accents) perform command substitution.

  3. To construct the name of a file located in the same directory as another:

      AOUTFILE=`dirname $TEXTFILE`/a.out

    This command sets the shell variable "AOUTFILE" to the name of an a.out
    file that is in the same directory as "TEXTFILE".  If "TEXTFILE" is
    "/u/fran/prog.c", the value of "dirname $TEXTFILE" is "/u/fran", and
    "AOUTFILE" becomes "/u/fran/a.out".

RELATED INFORMATION

See "sh, Rsh."








































Processed November 8, 1990  BASENAME, DIRNAME(1,C)                            2



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