basename – strip directory and suffix from filenames

A UNIX Command
basename: missing operand
Try `basename --help' for more information.
$basename /usr/bin/
$basename /usr/
$basename /usr/bin/less
$basename /usr/include/ma
malloc.h  math.h
$basename /usr/include/math.h
$basename /usr/include/math.h .
$basename /usr/include/math.h .h
$basename /usr/lib/
$basename /usr/lib/ .1

UNIX Explanation
`basename' removes any leading directory components from NAME.

     basename NAME [SUFFIX]

If SUFFIX  is specified  and is identical  to the  end of
NAME, it is  removed from NAME as well.   Note that since
trailing  slashes are removed  prior to  suffix matching,
SUFFIX   will  do   nothing  if   it   contains  slashes.
`basename' prints the result on standard output.

Together, `basename' and `dirname' are designed such that
if `ls  "$name"' succeeds, then the  command sequence `cd
"$(dirname  "$name")";  ls  "$(basename "$name")"'  will,
too.   This  works   for  everything  except  file  names
containing a trailing newline.

POSIX allows the implementation  to define the results if
NAME  is  empty  or   `//'.   In  the  former  case,  GNU
`basename' returns the empty string.  In the latter case,
the result is `//' on platforms where // is distinct from
/, and `/' on platforms where there is no difference.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: