Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ basename(1) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sh

basename, dirname

PURPOSE

     Returns the base name of a string parameter.

SYNOPSIS
     basename string [ suffix ]
     dirname string


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.

     Note:  A  basename of  "/" is null  and is  considered an
     error.

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

     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 displays the base name  of the value assigned to
         the shell variable "WORKFILE".   If "WORKFILE" is set
         to "/u/jim/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 assigns to "OFILE" the  value of the first posi-
         tional  parameter ("$1"),  but with  its ".c"  suffix
         changed to ".o".  If "$1" is "/u/jim/program.c", then
         "OFILE" becomes "program.o".   Because "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 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", then
         the  value of  "dirname $TEXTFILE"  is "/u/fran"  and
         "AOUTFILE" becomes "/u/fran/a.out".

RELATED INFORMATION

     The following command:  "sh."

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