Basename
Encyclopedia
basename is a standard UNIX
computer program
. When basename is given a pathname, it will delete any prefix up to the last slash (
and is primarily used in shell script
s.
specification for basename is.
basename string [suffix]
base.wiki
$ basename /home/jsmith/base.wiki .wiki
base
of shell scripts can be detrimental to performance. Consider
while read file; do
basename "$file"
done < some-input
The above excerpt would cause a separate process invocation for each line of input. For this reason, shell substitution is typically used instead
echo "${file##*/}";
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
computer program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
. When basename is given a pathname, it will delete any prefix up to the last slash (
'/'
) character and return the result. basename is described in the Single UNIX SpecificationSingle UNIX Specification
The Single UNIX Specification is the collective name of a family of standards for computer operating systems to qualify for the name "Unix"...
and is primarily used in shell script
Shell script
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...
s.
Usage
The Single UNIX SpecificationSingle UNIX Specification
The Single UNIX Specification is the collective name of a family of standards for computer operating systems to qualify for the name "Unix"...
specification for basename is.
basename string [suffix]
- string
- A pathname
- suffix
- If specified, basename will also delete the suffix.
Example
$ basename /home/jsmith/base.wikibase.wiki
$ basename /home/jsmith/base.wiki .wiki
base
Performance
Since basename accepts only one operand, its usage within the inner loopInner loop
In computer programs, an important form of control flow is the loop. For example, this small pseudo-code program uses two nested loops to iterate over all the entries of an n×n matrix, changing their values so that the matrix becomes an identity matrix: for a in 1..n for b in 1..n ...
of shell scripts can be detrimental to performance. Consider
while read file; do
basename "$file"
done < some-input
The above excerpt would cause a separate process invocation for each line of input. For this reason, shell substitution is typically used instead
echo "${file##*/}";