Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ basename(1) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

dirname(1)

ed(1)

sh(1)

basename(1)                                                     basename(1)

NAME
     basename - strip file name affixes

SYNOPSIS
     basename string [suffix]

DESCRIPTION
     You can use basename to

     -  extract the basic file name (basename) from the full path name,

     -  strip any suffixes from the file name.

     basename strips all characters up to and including the last / from the
     specified string and writes the result to standard output. The basic
     file name can thus be separated from its path prefix. If you also
     specify a string suffix as a command-line argument, basename will
     strip this suffix as well. basename is useful within backquotes `...`
     in shell scripts [see sh(1)].

OPERANDS
     string
          string can be any character string.

          basename deletes all characters up to and including the last /
          from string and writes the result to standard output. Strings
          that do not include a slash are output unmodified.

     suffix
          suffix can be any character string.

          If the specified suffix matches the end of string, string is out-
          put without suffix.

LOCALE
     The LCMESSAGES environment variable governs the language in which
     message texts are displayed. If LCMESSAGES is undefined or is defined
     as the null string, it defaults to the value of LANG. If LANG is like-
     wise undefined or null, the system acts as if it were not internation-
     alized.

     The LCALL environment variable governs the entire locale. LCALL
     takes precedence over all the other environment variables which affect
     internationalization.

EXAMPLES
     Example 1

     The name prog is to be generated from /home/catherine/program:

     $ basename /home/catherine/program ram
     prog



Page 1                       Reliant UNIX 5.44                Printed 11/98

basename(1)                                                     basename(1)

     Example 2

     The following shell script compiles a C source program. basename gen-
     erates the name of the compiled program from the file name used as a
     command-line argument for the shell script. The compiled program is
     stored in an executable file in the current working directory. The
     shell script is called compile.

     Contents of compile:

     cc -o `basename $1 .c` $1

     If you call compile as follows:

     $ compile /home/anna/cprogs/tab.c

     the file name of the C source file is passed to the cc command [con-
     trol program for compiling and linking C programs, see cc(1)] as posi-
     tional parameter $1 [see sh(1)]. The shell substitutes the output of
     basename for the operand of cc's -o option. The name of the executable
     file is tab.

SEE ALSO
     dirname(1), ed(1), sh(1).






























Page 2                       Reliant UNIX 5.44                Printed 11/98

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