Unix and Linux Discussions Tagged with basename |
|
Thread / Thread Starter |
Last Post |
Replies |
Views |
Forum |
|
|
|
2 |
5,750 |
Shell Programming and Scripting |
|
|
|
4 |
5,754 |
Shell Programming and Scripting |
|
|
|
2 |
11,646 |
Shell Programming and Scripting |
|
|
|
10 |
16,965 |
UNIX for Dummies Questions & Answers |
|
|
|
3 |
4,600 |
Shell Programming and Scripting |
|
|
|
4 |
108,074 |
Shell Programming and Scripting |
|
|
|
5 |
13,311 |
Shell Programming and Scripting |
|
|
|
2 |
2,215 |
Shell Programming and Scripting |
|
|
|
4 |
16,132 |
Shell Programming and Scripting |
|
|
|
2 |
2,746 |
Shell Programming and Scripting |
|
|
|
13 |
15,835 |
UNIX for Dummies Questions & Answers |
|
|
|
2 |
125,546 |
UNIX for Dummies Questions & Answers |
|
|
|
2 |
7,499 |
UNIX for Dummies Questions & Answers |
|
|
|
2 |
3,349 |
UNIX for Advanced & Expert Users |
|
|
|
1 |
4,578 |
UNIX for Dummies Questions & Answers |
|
|
|
4 |
3,914 |
UNIX for Dummies Questions & Answers |
|
|
|
4 |
5,955 |
UNIX for Advanced & Expert Users |
|
|
|
1 |
2,710 |
UNIX for Dummies Questions & Answers |
|
|
|
5 |
6,712 |
UNIX for Dummies Questions & Answers |
|
|
|
2 |
4,463 |
UNIX for Dummies Questions & Answers |
|
|
|
4 |
14,443 |
UNIX for Dummies Questions & Answers |
basename(1) General Commands Manual basename(1)
Name
basename - strip directory names from pathname
Syntax
basename string [ suffix ]
Description
The command deletes from string any prefix up to and including the last slash (/) and the suffix (if specified), and prints the result on
the standard output. The command handles limited regular expressions in the same manner as metacharacters must be escaped if they are
intended to be interpreted literally. For example:
% basename /vmunix .x
vmun
% basename /vmunix '.x'
vmunix
In the first example, returns because it interprets the as a regular expression consisting of any character followed by the letter In the
second example, the dot is escaped; there is no match on a dot followed by and returns
The command is often used inside substitution marks (` `) within shell procedures.
Examples
The following example shell script compiles the file and moves the output to in the current directory:
cc /usr/src/bin/cat.c
mv a.out `basename $1 .c`
The following example echoes only the base name of the file by removing the prefix and any possible sequence of characters following the
period in the file's name:
% basename /etc/syslog.conf '..*'
syslog
See Also
dirname(1), ex(1), sh(1)
basename(1)