Previous | Table of Contents | Next |
DESCRIPTION
The external basename command parses the given path and returns only the filename. Any prefix ending in / (slash) is deleted from the path . If a second argument is present, it is used as a suffix to be deleted from the filename. For instance, the command
cj> basename /u1/ts/mylogin/junk.c \.c junk
returns junk. The entire path (/u1/tech/mylogin/) and the .c suffix are removed.
The longest possible prefix is removed while the shortest possible suffix is deleted.
COMMAND FORMAT
Following is the format of the basename command.
basename path [ suffix ]
Arguments
Only two arguments may be passed to the basename command.
path | The path that is parsed with only the filename being returned. |
suffix | A suffix string that is removed from the end of the filename. |
RELATED COMMANDS
Refer to the dirname command described in Module 35.
RELATED FILES
The basename command writes to the standard output.
APPLICATIONS
The basename command is normally used as a substitution command within a shell script. It can be used to reduce a full path parameter or variable down to a single filename. It can also remove suffixes so a single parameter variable can be used to perform a task that uses the same filename with different suffixes.
TYPICAL OPERATION
In this activity you use the basename command to copy a file to a different directory and name . Begin at the shell prompt.
cj> cp $HOME/file1