📄 basename.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>basename</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_000_115"> </a>NAME</h4><blockquote>basename - return non-directory portion of a pathname</blockquote><h4><a name = "tag_000_000_116"> </a>SYNOPSIS</h4><blockquote><pre><code>basename <i>string </i><b>[</b><i>suffix</i><b>]</b></code></pre></blockquote><h4><a name = "tag_000_000_117"> </a>DESCRIPTION</h4><blockquote>The<i>string</i>operand will be treated as a pathname, as defined in<b>Pathname</b>.The string<i>string</i>will be converted to the filename corresponding tothe last pathname component in<i>string</i>and then the suffix string<i>suffix</i>,if present, will be removed.This will be done by performing actionsequivalent to the following steps in order:<ol><p><li>If<i>string</i>is<b>//</b>,it is implementation-dependent whether steps 2 to 5 areskipped or processed.<p><li>If<i>string</i>consists entirely of slash characters,<i>string</i>will be set to a single slash character.In this case, skip steps 3 to 5.<p><li>If there are any trailing slash characters in<i>string</i>,they will be removed.<p><li>If there are any slash characters remaining in<i>string</i>,the prefix of<i>string</i>up to and including the last slash character in<i>string</i>will be removed.<p><li>If the<i>suffix</i>operand is present, is not identicalto the characters remaining in<i>string</i>,and is identical to a suffix of the characters remaining in<i>string</i>,the suffix<i>suffix</i>will be removed from<i>string</i>.Otherwise,<i>string</i>will not be modified by this step.It will not be considered an error if<i>suffix</i>is not found in<i>string</i>.<p></ol><p>The resulting string will be written to standard output.</blockquote><h4><a name = "tag_000_000_118"> </a>OPTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_000_119"> </a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><i>string</i><dd>A string.<dt><i>suffix</i><dd>A string.</dl></blockquote><h4><a name = "tag_000_000_120"> </a>STDIN</h4><blockquote>Not used.</blockquote><h4><a name = "tag_000_000_121"> </a>INPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_000_122"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>basename</i>:<dl compact><dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard error.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i></dl></blockquote><h4><a name = "tag_000_000_123"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_000_000_124"> </a>STDOUT</h4><blockquote>The<i>basename</i>utility will write a line to the standard outputin the following format:<code><p><tt>"%s\n"</tt>, <<i>resulting string</i>></code></blockquote><h4><a name = "tag_000_000_125"> </a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_000_000_126"> </a>OUTPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_000_127"> </a>EXTENDED DESCRIPTION</h4><blockquote>None.</blockquote><h4><a name = "tag_000_000_128"> </a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>Successful completion.<dt>>0<dd>An error occurred.</dl></blockquote><h4><a name = "tag_000_000_129"> </a>CONSEQUENCES OF ERRORS</h4><blockquote>Default.</blockquote><h4><a name = "tag_000_000_130"> </a>APPLICATION USAGE</h4><blockquote>The definition of<i>pathname</i>specifies implementation-dependent behaviour for pathnamesstarting with two slash characters.Therefore, applications must not arbitrarily add slashesto the beginning of a pathname unless they can ensurethat there are more or less than two or are preparedto deal with the implementation-dependent consequences.</blockquote><h4><a name = "tag_000_000_131"> </a>EXAMPLES</h4><blockquote>If the string<i>string</i>is a valid pathname:<pre><code>$(basename "string")</code></pre>produces a filename that could be used to open the file named by<i>string</i>in the directory returned by:<pre><code>$(dirname "string")</code></pre><p>If the string<i>string</i>is not a valid pathname, the same algorithmis used, but the result need not be a valid filename.The<i>basename</i>utility is not expected to make any judgements aboutthe validity of<i>string</i>as a pathname; it just follows thespecified algorithm to produce a result string.<p>The following shell script compiles<b>/usr/src/cmd/cat.c</b>and moves the output to a file named<b>cat</b>in the current directory wheninvoked with the argument/usr/src/cmd/cator with the argument/usr/src/cmd/cat.c:<pre><code>c89 $(dirname "$1")/$(basename "$1" .c).cmv a.out $(basename "$1" .c)</code></pre></blockquote><h4><a name = "tag_000_000_132"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_000_133"> </a>SEE ALSO</h4><blockquote><i><a href="dirname.html">dirname</a></i>,<xref href=parms><a href="chap2.html#tag_001_005">Parameters and Variables</a></xref>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -