isposix

Un outil pour savoir si une commande est posix - retour accueil

git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |

realpath.html (13503B)


      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>realpath</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/readlink.html" accesskey="P">&lt;&lt;&lt;
     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/renice.html" accesskey="N">Next
     19 &gt;&gt;&gt;</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="realpath" id="realpath"></a> <a name="tag_20_102" id="tag_20_102"></a><!-- realpath -->
     29 <h4 class="mansect"><a name="tag_20_102_01" id="tag_20_102_01"></a>NAME</h4>
     30 <blockquote>realpath — resolve a pathname</blockquote>
     31 <h4 class="mansect"><a name="tag_20_102_02" id="tag_20_102_02"></a>SYNOPSIS</h4>
     32 <blockquote class="synopsis">
     33 <p><code><tt>realpath</tt> <b>[</b><tt>-E|-e</tt><b>]</b> <i>file</i></code></p>
     34 </blockquote>
     35 <h4 class="mansect"><a name="tag_20_102_03" id="tag_20_102_03"></a>DESCRIPTION</h4>
     36 <blockquote>
     37 <p>The <i>realpath</i> utility shall canonicalize the pathname specified by the <i>file</i> operand as follows:</p>
     38 <p>If a call to the <a href="../functions/realpath.html"><i>realpath</i>()</a> function with the specified pathname as its first
     39 argument would succeed, the canonicalized pathname shall be the pathname that would be returned by that <a href=
     40 "../functions/realpath.html"><i>realpath</i>()</a> call. Otherwise:</p>
     41 <ul>
     42 <li>
     43 <p>If the <b>-e</b> option is specified, the canonicalization shall fail.</p>
     44 </li>
     45 <li>
     46 <p>If the <b>-E</b> option is specified, then if a call to the <a href="../functions/realpath.html"><i>realpath</i>()</a> function
     47 with the specified pathname as its first argument would encounter an error condition other than [ENOENT], the canonicalization
     48 shall fail; if the call would encounter an [ENOENT] error, <i>realpath</i> shall expand all symbolic links that would be
     49 encountered in an attempt to resolve the specified pathname using the algorithm specified in XBD <a href=
     50 "../basedefs/V1_chap04.html#tag_04_16"><i>4.16 Pathname Resolution</i></a> , except that any trailing &lt;slash&gt; characters that
     51 are not also leading &lt;slash&gt; characters shall be ignored. If this expansion succeeds and the path prefix of the expanded
     52 pathname resolves to an existing directory, the canonicalized pathname shall be the expanded pathname. In all other cases, the
     53 canonicalization shall fail. If the expanded pathname is not empty, does not begin with a &lt;slash&gt;, and has exactly one
     54 pathname component, it shall be treated as if it had a path prefix of <tt>"./"</tt>.</p>
     55 </li>
     56 <li>
     57 <p>If no options are specified, <i>realpath</i> shall canonicalize the specified pathname in an unspecified manner such that the
     58 resulting absolute pathname does not contain any components that refer to files of type symbolic link and does not contain any
     59 components that are dot or dot-dot.</p>
     60 </li>
     61 </ul>
     62 <p>Upon successful canonicalization, <i>realpath</i> shall write the canonicalized pathname, followed by a &lt;newline&gt;
     63 character, to standard output.</p>
     64 <p>If canonicalization fails, or the canonicalized pathname is empty, nothing shall be written to standard output, a diagnostic
     65 message shall be written to standard error, and <i>realpath</i> shall exit with non-zero status.</p>
     66 </blockquote>
     67 <h4 class="mansect"><a name="tag_20_102_04" id="tag_20_102_04"></a>OPTIONS</h4>
     68 <blockquote>
     69 <p>The <i>realpath</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     70 Guidelines</i></a> .</p>
     71 <p>The following options shall be supported:</p>
     72 <dl compact>
     73 <dd></dd>
     74 <dt><b>-E</b></dt>
     75 <dd>Do not treat it as an error if attempting to resolve the last component of the canonicalized form of the <i>file</i> operand
     76 results in an [ENOENT] error condition.</dd>
     77 <dt><b>-e</b></dt>
     78 <dd>Treat it as an error if attempting to resolve the last component of the canonicalized form of the <i>file</i> operand results
     79 in an [ENOENT] error condition.</dd>
     80 </dl>
     81 <p>Specifying more than one of the mutually-exclusive options <b>-E</b> and <b>-e</b> shall not be considered an error. The last
     82 option specified shall determine the behavior of the utility.</p>
     83 </blockquote>
     84 <h4 class="mansect"><a name="tag_20_102_05" id="tag_20_102_05"></a>OPERANDS</h4>
     85 <blockquote>
     86 <p>The following operand shall be supported:</p>
     87 <dl compact>
     88 <dd></dd>
     89 <dt><i>file</i></dt>
     90 <dd>A pathname to be canonicalized.</dd>
     91 </dl>
     92 </blockquote>
     93 <h4 class="mansect"><a name="tag_20_102_06" id="tag_20_102_06"></a>STDIN</h4>
     94 <blockquote>
     95 <p>Not used.</p>
     96 </blockquote>
     97 <h4 class="mansect"><a name="tag_20_102_07" id="tag_20_102_07"></a>INPUT FILES</h4>
     98 <blockquote>
     99 <p>None.</p>
    100 </blockquote>
    101 <h4 class="mansect"><a name="tag_20_102_08" id="tag_20_102_08"></a>ENVIRONMENT VARIABLES</h4>
    102 <blockquote>
    103 <p>The following environment variables shall affect the execution of <i>realpath</i>:</p>
    104 <dl compact>
    105 <dd></dd>
    106 <dt><i>LANG</i></dt>
    107 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
    108 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
    109 variables used to determine the values of locale categories.)</dd>
    110 <dt><i>LC_ALL</i></dt>
    111 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
    112 <dt><i>LC_CTYPE</i></dt>
    113 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
    114 opposed to multi-byte characters in arguments and input files).</dd>
    115 <dt><i>LC_MESSAGES</i></dt>
    116 <dd><br>
    117 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
    118 <dt><i>NLSPATH</i></dt>
    119 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    120 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    121 "0"></dd>
    122 </dl>
    123 </blockquote>
    124 <h4 class="mansect"><a name="tag_20_102_09" id="tag_20_102_09"></a>ASYNCHRONOUS EVENTS</h4>
    125 <blockquote>
    126 <p>Default.</p>
    127 </blockquote>
    128 <h4 class="mansect"><a name="tag_20_102_10" id="tag_20_102_10"></a>STDOUT</h4>
    129 <blockquote>
    130 <p>See DESCRIPTION.</p>
    131 </blockquote>
    132 <h4 class="mansect"><a name="tag_20_102_11" id="tag_20_102_11"></a>STDERR</h4>
    133 <blockquote>
    134 <p>The standard error shall be used only for diagnostic messages.</p>
    135 </blockquote>
    136 <h4 class="mansect"><a name="tag_20_102_12" id="tag_20_102_12"></a>OUTPUT FILES</h4>
    137 <blockquote>
    138 <p>None.</p>
    139 </blockquote>
    140 <h4 class="mansect"><a name="tag_20_102_13" id="tag_20_102_13"></a>EXTENDED DESCRIPTION</h4>
    141 <blockquote>
    142 <p>None.</p>
    143 </blockquote>
    144 <h4 class="mansect"><a name="tag_20_102_14" id="tag_20_102_14"></a>EXIT STATUS</h4>
    145 <blockquote>
    146 <p>The following exit values shall be returned:</p>
    147 <dl compact>
    148 <dd></dd>
    149 <dt>&nbsp;0</dt>
    150 <dd>Successful completion.</dd>
    151 <dt>&gt;0</dt>
    152 <dd>An error occurred.</dd>
    153 </dl>
    154 </blockquote>
    155 <h4 class="mansect"><a name="tag_20_102_15" id="tag_20_102_15"></a>CONSEQUENCES OF ERRORS</h4>
    156 <blockquote>
    157 <p>Default.</p>
    158 </blockquote>
    159 <hr>
    160 <div class="box"><em>The following sections are informative.</em></div>
    161 <h4 class="mansect"><a name="tag_20_102_16" id="tag_20_102_16"></a>APPLICATION USAGE</h4>
    162 <blockquote>
    163 <p>If neither the <b>-e</b> nor the <b>-E</b> option is specified, some implementations behave as if <b>-e</b> had been specified
    164 and others as if <b>-E</b> had been specified, but there are also implementations where the behavior differs from both of these.
    165 For example, the <i>mksh</i> shell has an internal implementation of <i>realpath</i> that canonicalizes <b>/dir/regular_file/..</b>
    166 to <b>/dir</b>, whereas the <a href="../functions/realpath.html"><i>realpath</i>()</a> function would return an [ENOTDIR] error in
    167 this case. Portable applications should always specify either <b>-e</b> or <b>-E</b>.</p>
    168 </blockquote>
    169 <h4 class="mansect"><a name="tag_20_102_17" id="tag_20_102_17"></a>EXAMPLES</h4>
    170 <blockquote>
    171 <p>None.</p>
    172 </blockquote>
    173 <h4 class="mansect"><a name="tag_20_102_18" id="tag_20_102_18"></a>RATIONALE</h4>
    174 <blockquote>
    175 <p>The <i>realpath</i> utility was added in preference to a <b>-f</b> option found in some implementations of the <a href=
    176 "../utilities/readlink.html"><i>readlink</i></a> utility because it allows the application to specify whether or not a missing
    177 final component is to be treated as an error.</p>
    178 <p>The behavior with the <b>-E</b> option when <i>file</i> does not resolve (with symbolic links followed) to an existing file is
    179 not the same as simply calling <a href="../functions/realpath.html"><i>realpath</i>()</a> with the path prefix of the <i>file</i>
    180 operand and writing the resulting pathname, a &lt;slash&gt;, and the last component of <i>file</i> to standard output. For example,
    181 if <b>/tmp/nofile</b> does not exist, and <i>file</i> is <b>A/B</b> where <b>A</b> is an existing directory and <b>B</b> is a
    182 symbolic link to <b>/tmp/nofile</b>, <i>realpath</i> with <b>-E</b> will output <b>/tmp/nofile</b>, but if <b>B</b> is a symbolic
    183 link to <b>/tmp/nofile/foo</b>, <i>realpath</i> with <b>-E</b> will treat this as an error. In both cases <tt>realpath("A/B")</tt>
    184 would fail with <i>errno</i> set to [ENOENT]. Even though <tt>realpath("A")</tt> would succeed, in neither case is anything ending
    185 <b>/B</b> the result.</p>
    186 <p>Trailing &lt;slash&gt; characters (that follow a non-&lt;slash&gt;) are handled differently with <b>-E</b> than with <b>-e</b>.
    187 With <b>-e</b> they are handled as for the <a href="../functions/realpath.html"><i>realpath</i>()</a> function. With <b>-E</b> they
    188 are sometimes effectively ignored, and they are never included in the output. For example, if <b>/tmp/nofile</b> does not exist and
    189 <b>/tmp/regfile</b> is an existing regular file:</p>
    190 <pre>
    191 <tt>$ realpath -E /tmp/nofile/
    192 /tmp/nofile
    193 $ realpath -E /tmp/regfile/
    194 realpath: /tmp/regfile/: Not a directory
    195 </tt></pre></blockquote>
    196 <h4 class="mansect"><a name="tag_20_102_19" id="tag_20_102_19"></a>FUTURE DIRECTIONS</h4>
    197 <blockquote>
    198 <p>If this utility is directed to display a pathname that contains any bytes that have the encoded value of a &lt;newline&gt;
    199 character when &lt;newline&gt; is a terminator or separator in the output format being used, implementations are encouraged to
    200 treat this as an error. A future version of this standard may require implementations to treat this as an error.</p>
    201 </blockquote>
    202 <h4 class="mansect"><a name="tag_20_102_20" id="tag_20_102_20"></a>SEE ALSO</h4>
    203 <blockquote>
    204 <p><a href="../utilities/ln.html#"><i>ln</i></a> , <a href="../utilities/ls.html#"><i>ls</i></a> , <a href=
    205 "../utilities/pwd.html#"><i>pwd</i></a> , <a href="../utilities/readlink.html#tag_20_101"><i>readlink</i></a></p>
    206 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    207 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    208 <p>XSH <a href="../functions/V2_chap02.html#tag_16_03"><i>2.3 Error Numbers</i></a> , <a href=
    209 "../functions/realpath.html#"><i>realpath</i></a></p>
    210 </blockquote>
    211 <h4 class="mansect"><a name="tag_20_102_21" id="tag_20_102_21"></a>CHANGE HISTORY</h4>
    212 <blockquote>
    213 <p>First released in Issue 8.</p>
    214 </blockquote>
    215 <div class="box"><em>End of informative text.</em></div>
    216 <hr>
    217 <p>&nbsp;</p>
    218 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    219 <hr size="2" noshade>
    220 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    221 POSIX™ is a Trademark of The IEEE.<br>
    222 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    223 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    224 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    225 ]</font></center>
    226 <hr size="2" noshade>
    227 <div class="NAVHEADER">
    228 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    229 <tr class="nav">
    230 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/readlink.html" accesskey="P">&lt;&lt;&lt;
    231 Previous</a></td>
    232 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    233 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/renice.html" accesskey="N">Next
    234 &gt;&gt;&gt;</a></td>
    235 </tr>
    236 </table>
    237 <hr align="left" width="100%"></div>
    238 </body>
    239 </html>