Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
basename.html (13511B)
1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved --> 2 <!DOCTYPE HTML> 3 <html lang="en"> 4 <head> 5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0"> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 --> 8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved --> 9 <title>basename</title> 10 </head> 11 <body bgcolor="white"> 12 <div class="NAVHEADER"> 13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 14 <tr class="nav"> 15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/awk.html" accesskey="P"><<< 16 Previous</a></td> 17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/batch.html" accesskey="N">Next 19 >>></a></td> 20 </tr> 21 </table> 22 <hr align="left" width="100%"></div> 23 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> 24 <center><font size="2">The Open Group Base Specifications Issue 8<br> 25 IEEE Std 1003.1-2024<br> 26 Copyright © 2001-2024 The IEEE and The Open Group</font></center> 27 <hr size="2" noshade> 28 <a name="top" id="top"></a> <a name="basename" id="basename"></a> <a name="tag_20_07" id="tag_20_07"></a><!-- basename --> 29 <h4 class="mansect"><a name="tag_20_07_01" id="tag_20_07_01"></a>NAME</h4> 30 <blockquote>basename — return non-directory portion of a pathname</blockquote> 31 <h4 class="mansect"><a name="tag_20_07_02" id="tag_20_07_02"></a>SYNOPSIS</h4> 32 <blockquote class="synopsis"> 33 <p><code><tt>basename</tt> <i>string</i> <b>[</b><i>suffix</i><b>]</b></code></p> 34 </blockquote> 35 <h4 class="mansect"><a name="tag_20_07_03" id="tag_20_07_03"></a>DESCRIPTION</h4> 36 <blockquote> 37 <p>The <i>string</i> operand shall be treated as a pathname, as defined in XBD <a href= 38 "../basedefs/V1_chap03.html#tag_03_254"><i>3.254 Pathname</i></a> . The string <i>string</i> shall be converted to the filename 39 corresponding to the last pathname component in <i>string</i> and then the suffix string <i>suffix</i>, if present, shall be 40 removed. This shall be done by performing actions equivalent to the following steps in order:</p> 41 <ol> 42 <li> 43 <p>If <i>string</i> is a null string, it is unspecified whether the resulting string is <tt>'.'</tt> or a null string. In either 44 case, skip steps 2 through 6.</p> 45 </li> 46 <li> 47 <p>If <i>string</i> is <tt>"//"</tt>, it is implementation-defined whether steps 3 to 6 are skipped or processed.</p> 48 </li> 49 <li> 50 <p>If <i>string</i> consists entirely of <slash> characters, <i>string</i> shall be set to a single <slash> character. 51 In this case, skip steps 4 to 6.</p> 52 </li> 53 <li> 54 <p>If there are any trailing <slash> characters in <i>string</i>, they shall be removed.</p> 55 </li> 56 <li> 57 <p>If there are any <slash> characters remaining in <i>string</i>, the prefix of <i>string</i> up to and including the last 58 <slash> character in <i>string</i> shall be removed.</p> 59 </li> 60 <li> 61 <p>If the <i>suffix</i> operand is present, is not identical to the characters remaining in <i>string</i>, and is identical to a 62 suffix of the characters remaining in <i>string</i>, the suffix <i>suffix</i> shall be removed from <i>string</i>. Otherwise, 63 <i>string</i> is not modified by this step. It shall not be considered an error if <i>suffix</i> is not found in <i>string</i>.</p> 64 </li> 65 </ol> 66 <p>The resulting string shall be written to standard output.</p> 67 </blockquote> 68 <h4 class="mansect"><a name="tag_20_07_04" id="tag_20_07_04"></a>OPTIONS</h4> 69 <blockquote> 70 <p>None.</p> 71 </blockquote> 72 <h4 class="mansect"><a name="tag_20_07_05" id="tag_20_07_05"></a>OPERANDS</h4> 73 <blockquote> 74 <p>The following operands shall be supported:</p> 75 <dl compact> 76 <dd></dd> 77 <dt><i>string</i></dt> 78 <dd>A string.</dd> 79 <dt><i>suffix</i></dt> 80 <dd>A string.</dd> 81 </dl> 82 </blockquote> 83 <h4 class="mansect"><a name="tag_20_07_06" id="tag_20_07_06"></a>STDIN</h4> 84 <blockquote> 85 <p>Not used.</p> 86 </blockquote> 87 <h4 class="mansect"><a name="tag_20_07_07" id="tag_20_07_07"></a>INPUT FILES</h4> 88 <blockquote> 89 <p>None.</p> 90 </blockquote> 91 <h4 class="mansect"><a name="tag_20_07_08" id="tag_20_07_08"></a>ENVIRONMENT VARIABLES</h4> 92 <blockquote> 93 <p>The following environment variables shall affect the execution of <i>basename</i>:</p> 94 <dl compact> 95 <dd></dd> 96 <dt><i>LANG</i></dt> 97 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 98 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization 99 variables used to determine the values of locale categories.)</dd> 100 <dt><i>LC_ALL</i></dt> 101 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 102 <dt><i>LC_CTYPE</i></dt> 103 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 104 opposed to multi-byte characters in arguments).</dd> 105 <dt><i>LC_MESSAGES</i></dt> 106 <dd><br> 107 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd> 108 <dt><i>NLSPATH</i></dt> 109 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 110 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 111 "0"></dd> 112 </dl> 113 </blockquote> 114 <h4 class="mansect"><a name="tag_20_07_09" id="tag_20_07_09"></a>ASYNCHRONOUS EVENTS</h4> 115 <blockquote> 116 <p>Default.</p> 117 </blockquote> 118 <h4 class="mansect"><a name="tag_20_07_10" id="tag_20_07_10"></a>STDOUT</h4> 119 <blockquote> 120 <p>The <i>basename</i> utility shall write a line to the standard output in the following format:</p> 121 <pre> 122 <tt>"%s\n", <</tt><i>resulting string</i><tt>> 123 </tt></pre></blockquote> 124 <h4 class="mansect"><a name="tag_20_07_11" id="tag_20_07_11"></a>STDERR</h4> 125 <blockquote> 126 <p>The standard error shall be used only for diagnostic messages.</p> 127 </blockquote> 128 <h4 class="mansect"><a name="tag_20_07_12" id="tag_20_07_12"></a>OUTPUT FILES</h4> 129 <blockquote> 130 <p>None.</p> 131 </blockquote> 132 <h4 class="mansect"><a name="tag_20_07_13" id="tag_20_07_13"></a>EXTENDED DESCRIPTION</h4> 133 <blockquote> 134 <p>None.</p> 135 </blockquote> 136 <h4 class="mansect"><a name="tag_20_07_14" id="tag_20_07_14"></a>EXIT STATUS</h4> 137 <blockquote> 138 <p>The following exit values shall be returned:</p> 139 <dl compact> 140 <dd></dd> 141 <dt> 0</dt> 142 <dd>Successful completion.</dd> 143 <dt>>0</dt> 144 <dd>An error occurred.</dd> 145 </dl> 146 </blockquote> 147 <h4 class="mansect"><a name="tag_20_07_15" id="tag_20_07_15"></a>CONSEQUENCES OF ERRORS</h4> 148 <blockquote> 149 <p>Default.</p> 150 </blockquote> 151 <hr> 152 <div class="box"><em>The following sections are informative.</em></div> 153 <h4 class="mansect"><a name="tag_20_07_16" id="tag_20_07_16"></a>APPLICATION USAGE</h4> 154 <blockquote> 155 <p>The definition of <i>pathname</i> specifies implementation-defined behavior for pathnames starting with two <slash> 156 characters. Therefore, applications shall not arbitrarily add <slash> characters to the beginning of a pathname unless they 157 can ensure that there are more or less than two or are prepared to deal with the implementation-defined consequences.</p> 158 </blockquote> 159 <h4 class="mansect"><a name="tag_20_07_17" id="tag_20_07_17"></a>EXAMPLES</h4> 160 <blockquote> 161 <p>If the string <i>string</i> is a valid pathname:</p> 162 <pre> 163 <tt>$(basename -- "</tt><i>string</i><tt>") 164 </tt></pre> 165 <p>produces a filename that could be used to open the file named by <i>string</i> in the directory returned by:</p> 166 <pre> 167 <tt>$(dirname -- "</tt><i>string</i><tt>") 168 </tt></pre> 169 <p>If the string <i>string</i> is not a valid pathname, the same algorithm is used, but the result need not be a valid filename. 170 The <i>basename</i> utility is not expected to make any judgements about the validity of <i>string</i> as a pathname; it just 171 follows the specified algorithm to produce a result string.</p> 172 <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 173 directory when invoked with the argument <b>/usr/src/cmd/cat</b> or with the argument <b>/usr/src/cmd/cat.c</b>:</p> 174 <pre> 175 <tt>c17 -- "$(dirname -- "$1")/$(basename -- "$1" .c).c" && 176 mv a.out "$(basename -- "$1" .c)" 177 </tt></pre> 178 <p>The EXAMPLES section of the <a href="../functions/basename.html"><i>basename</i>()</a> function (see XSH <a href= 179 "../functions/basename.html#tag_17_42"><i>basename</i></a> ) includes a table showing examples of the results of processing several 180 sample pathnames by the <a href="../functions/basename.html"><i>basename</i>()</a> and <a href= 181 "../functions/dirname.html"><i>dirname</i>()</a> functions and by the <i>basename</i> and <a href= 182 "../utilities/dirname.html"><i>dirname</i></a> utilities.</p> 183 </blockquote> 184 <h4 class="mansect"><a name="tag_20_07_18" id="tag_20_07_18"></a>RATIONALE</h4> 185 <blockquote> 186 <p>The behaviors of <i>basename</i> and <a href="../utilities/dirname.html"><i>dirname</i></a> have been coordinated so that when 187 <i>string</i> is a valid pathname:</p> 188 <pre> 189 <tt>$(basename -- "</tt><i>string</i><tt>") 190 </tt></pre> 191 <p>would be a valid filename for the file in the directory:</p> 192 <pre> 193 <tt>$(dirname -- "</tt><i>string</i><tt>") 194 </tt></pre> 195 <p>This would not work for the early proposal versions of these utilities due to the way it specified handling of trailing 196 <slash> characters.</p> 197 <p>Since the definition of <i>pathname</i> specifies implementation-defined behavior for pathnames starting with two <slash> 198 characters, this volume of POSIX.1-2024 specifies similar implementation-defined behavior for the <i>basename</i> and <a href= 199 "../utilities/dirname.html"><i>dirname</i></a> utilities.</p> 200 </blockquote> 201 <h4 class="mansect"><a name="tag_20_07_19" id="tag_20_07_19"></a>FUTURE DIRECTIONS</h4> 202 <blockquote> 203 <p>If this utility is directed to display a pathname that contains any bytes that have the encoded value of a <newline> 204 character when <newline> is a terminator or separator in the output format being used, implementations are encouraged to 205 treat this as an error. A future version of this standard may require implementations to treat this as an error.</p> 206 </blockquote> 207 <h4 class="mansect"><a name="tag_20_07_20" id="tag_20_07_20"></a>SEE ALSO</h4> 208 <blockquote> 209 <p><a href="../utilities/V3_chap02.html#tag_19_05"><i>2.5 Parameters and Variables</i></a> , <a href= 210 "../utilities/dirname.html#tag_20_35"><i>dirname</i></a></p> 211 <p>XBD <a href="../basedefs/V1_chap03.html#tag_03_254"><i>3.254 Pathname</i></a> , <a href= 212 "../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a></p> 213 <p>XSH <a href="../functions/basename.html#tag_17_42"><i>basename</i></a> , <a href= 214 "../functions/dirname.html#tag_17_108"><i>dirname</i></a></p> 215 </blockquote> 216 <h4 class="mansect"><a name="tag_20_07_21" id="tag_20_07_21"></a>CHANGE HISTORY</h4> 217 <blockquote> 218 <p>First released in Issue 2.</p> 219 </blockquote> 220 <h4 class="mansect"><a name="tag_20_07_22" id="tag_20_07_22"></a>Issue 6</h4> 221 <blockquote> 222 <p>IEEE PASC Interpretation 1003.2 #164 is applied.</p> 223 <p>The normative text is reworded to avoid use of the term "must" for application requirements.</p> 224 </blockquote> 225 <h4 class="mansect"><a name="tag_20_07_23" id="tag_20_07_23"></a>Issue 7</h4> 226 <blockquote> 227 <p>POSIX.1-2008, Technical Corrigendum 1, XCU/TC1-2008/0065 [192,538], XCU/TC1-2008/0066 [192,538], and XCU/TC1-2008/0067 228 [192,430,538] are applied.</p> 229 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0065 [612] is applied.</p> 230 </blockquote> 231 <h4 class="mansect"><a name="tag_20_07_24" id="tag_20_07_24"></a>Issue 8</h4> 232 <blockquote> 233 <p>Austin Group Defect 251 is applied, encouraging implementations to report an error if a utility is directed to display a 234 pathname that contains any bytes that have the encoded value of a <newline> character when <newline> is a terminator or 235 separator in the output format being used.</p> 236 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 237 </blockquote> 238 <div class="box"><em>End of informative text.</em></div> 239 <hr> 240 <p> </p> 241 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 242 <hr size="2" noshade> 243 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 244 POSIX™ is a Trademark of The IEEE.<br> 245 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 246 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 247 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 248 ]</font></center> 249 <hr size="2" noshade> 250 <div class="NAVHEADER"> 251 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 252 <tr class="nav"> 253 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/awk.html" accesskey="P"><<< 254 Previous</a></td> 255 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 256 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/batch.html" accesskey="N">Next 257 >>></a></td> 258 </tr> 259 </table> 260 <hr align="left" width="100%"></div> 261 </body> 262 </html>