Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
alias.html (14457B)
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>alias</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/admin.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/ar.html" accesskey="N">Next >>></a></td> 19 </tr> 20 </table> 21 <hr align="left" width="100%"></div> 22 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> 23 <center><font size="2">The Open Group Base Specifications Issue 8<br> 24 IEEE Std 1003.1-2024<br> 25 Copyright © 2001-2024 The IEEE and The Open Group</font></center> 26 <hr size="2" noshade> 27 <a name="top" id="top"></a> <a name="alias" id="alias"></a> <a name="tag_20_02" id="tag_20_02"></a><!-- alias --> 28 <h4 class="mansect"><a name="tag_20_02_01" id="tag_20_02_01"></a>NAME</h4> 29 <blockquote>alias — define or display aliases</blockquote> 30 <h4 class="mansect"><a name="tag_20_02_02" id="tag_20_02_02"></a>SYNOPSIS</h4> 31 <blockquote class="synopsis"> 32 <p><code><tt>alias</tt> <b>[</b><i>alias-name</i><b>[</b><tt>=</tt><i>string</i><b>]</b><tt>...</tt><b>]</b></code></p> 33 </blockquote> 34 <h4 class="mansect"><a name="tag_20_02_03" id="tag_20_02_03"></a>DESCRIPTION</h4> 35 <blockquote> 36 <p>The <i>alias</i> utility shall create or redefine alias definitions or write the values of existing alias definitions to 37 standard output. An alias definition provides a string value that shall replace a command name when it is encountered. For 38 information on valid string values, and the processing involved, see <a href="../utilities/V3_chap02.html#tag_19_03_01"><i>2.3.1 39 Alias Substitution</i></a> .</p> 40 <p>An alias definition shall affect the current shell execution environment and the execution environments of the subshells of the 41 current shell. When used as specified by this volume of POSIX.1-2024, the alias definition shall not affect the parent process of 42 the current shell nor any utility environment invoked by the shell; see <a href="../utilities/V3_chap02.html#tag_19_13"><i>2.13 43 Shell Execution Environment</i></a> .</p> 44 </blockquote> 45 <h4 class="mansect"><a name="tag_20_02_04" id="tag_20_02_04"></a>OPTIONS</h4> 46 <blockquote> 47 <p>None.</p> 48 </blockquote> 49 <h4 class="mansect"><a name="tag_20_02_05" id="tag_20_02_05"></a>OPERANDS</h4> 50 <blockquote> 51 <p>The following operands shall be supported:</p> 52 <dl compact> 53 <dd></dd> 54 <dt><i>alias-name</i></dt> 55 <dd>Write the alias definition to standard output.</dd> 56 <dt><i>alias-name</i>=<i>string</i></dt> 57 <dd><br> 58 Assign the value of <i>string</i> to the alias <i>alias-name</i>.</dd> 59 </dl> 60 <p>If no operands are given, all alias definitions shall be written to standard output.</p> 61 </blockquote> 62 <h4 class="mansect"><a name="tag_20_02_06" id="tag_20_02_06"></a>STDIN</h4> 63 <blockquote> 64 <p>Not used.</p> 65 </blockquote> 66 <h4 class="mansect"><a name="tag_20_02_07" id="tag_20_02_07"></a>INPUT FILES</h4> 67 <blockquote> 68 <p>None.</p> 69 </blockquote> 70 <h4 class="mansect"><a name="tag_20_02_08" id="tag_20_02_08"></a>ENVIRONMENT VARIABLES</h4> 71 <blockquote> 72 <p>The following environment variables shall affect the execution of <i>alias</i>:</p> 73 <dl compact> 74 <dd></dd> 75 <dt><i>LANG</i></dt> 76 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 77 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization 78 variables used to determine the values of locale categories.)</dd> 79 <dt><i>LC_ALL</i></dt> 80 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 81 <dt><i>LC_CTYPE</i></dt> 82 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 83 opposed to multi-byte characters in arguments).</dd> 84 <dt><i>LC_MESSAGES</i></dt> 85 <dd><br> 86 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd> 87 <dt><i>NLSPATH</i></dt> 88 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 89 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 90 "0"></dd> 91 </dl> 92 </blockquote> 93 <h4 class="mansect"><a name="tag_20_02_09" id="tag_20_02_09"></a>ASYNCHRONOUS EVENTS</h4> 94 <blockquote> 95 <p>Default.</p> 96 </blockquote> 97 <h4 class="mansect"><a name="tag_20_02_10" id="tag_20_02_10"></a>STDOUT</h4> 98 <blockquote> 99 <p>The format for displaying aliases (when no operands or only <i>name</i> operands are specified) shall be:</p> 100 <pre> 101 <tt>"%s=%s\n", </tt><i>name</i><tt>, </tt><i>value</i><tt> 102 </tt></pre> 103 <p>The <i>value</i> string shall be written with appropriate quoting so that it is suitable for reinput to the shell. See the 104 description of shell quoting in <a href="../utilities/V3_chap02.html#tag_19_02"><i>2.2 Quoting</i></a> .</p> 105 </blockquote> 106 <h4 class="mansect"><a name="tag_20_02_11" id="tag_20_02_11"></a>STDERR</h4> 107 <blockquote> 108 <p>The standard error shall be used only for diagnostic messages.</p> 109 </blockquote> 110 <h4 class="mansect"><a name="tag_20_02_12" id="tag_20_02_12"></a>OUTPUT FILES</h4> 111 <blockquote> 112 <p>None.</p> 113 </blockquote> 114 <h4 class="mansect"><a name="tag_20_02_13" id="tag_20_02_13"></a>EXTENDED DESCRIPTION</h4> 115 <blockquote> 116 <p>None.</p> 117 </blockquote> 118 <h4 class="mansect"><a name="tag_20_02_14" id="tag_20_02_14"></a>EXIT STATUS</h4> 119 <blockquote> 120 <p>The following exit values shall be returned:</p> 121 <dl compact> 122 <dd></dd> 123 <dt> 0</dt> 124 <dd>Successful completion.</dd> 125 <dt>>0</dt> 126 <dd>One of the <i>name</i> operands specified did not have an alias definition, or an error occurred.</dd> 127 </dl> 128 </blockquote> 129 <h4 class="mansect"><a name="tag_20_02_15" id="tag_20_02_15"></a>CONSEQUENCES OF ERRORS</h4> 130 <blockquote> 131 <p>Default.</p> 132 </blockquote> 133 <hr> 134 <div class="box"><em>The following sections are informative.</em></div> 135 <h4 class="mansect"><a name="tag_20_02_16" id="tag_20_02_16"></a>APPLICATION USAGE</h4> 136 <blockquote> 137 <p>This utility is required to be intrinsic. See <a href="../utilities/V3_chap01.html#tag_18_07"><i>1.7 Intrinsic Utilities</i></a> 138 for details.</p> 139 <p>Care should be taken to avoid alias values that end with a character that could be treated as part of an operator token, as it 140 is unspecified whether the character that follows the alias name in the input can be used as part of the same token (see <a href= 141 "../utilities/V3_chap02.html#tag_19_03_01"><i>2.3.1 Alias Substitution</i></a> ). For example, with:</p> 142 <pre> 143 <tt>$ alias foo='echo 0' 144 $ foo>&2 145 </tt></pre> 146 the shell can either pass the argument <tt>'0'</tt> to <a href="../utilities/echo.html"><i>echo</i></a> and redirect fd 1 to fd 2, 147 or pass no arguments to <a href="../utilities/echo.html"><i>echo</i></a> and redirect fd 0 to fd 2. Changing it to: 148 <pre> 149 <tt>$ alias foo='echo "0"' 150 </tt></pre> 151 avoids this problem. The alternative of adding a <space> after the <tt>'0'</tt> would also avoid the problem, but in addition 152 it would alter the way the alias works, as described in <a href="../utilities/V3_chap02.html#tag_19_03_01"><i>2.3.1 Alias 153 Substitution</i></a> . 154 <p>Likewise, given:</p> 155 <pre> 156 <tt>$ alias foo='some_command &' 157 $ foo& 158 </tt></pre> 159 the shell may combine the two <tt>'&'</tt> characters into an <tt>&&</tt> (and) operator. Since the alias cannot pass 160 arguments to <i>some_command</i> and thus can be expected to be invoked without arguments, adding a <space> after the 161 <tt>'&'</tt> would be an acceptable way to prevent this. Alternatively, the alias could be specified as a grouping command: 162 <pre> 163 <tt>$ alias foo='{ some_command & }' 164 </tt></pre> 165 <p>Problems can occur for tokens other than operators as well, if the alias is used in unusual ways. For example, with:</p> 166 <pre> 167 <tt>$ alias foo='echo $' 168 $ foo((123)) 169 </tt></pre> 170 some shells combine the <tt>'$'</tt> and the <tt>"((123))"</tt> to form an arithmetic expansion, but others do not (resulting in a 171 syntax error).</blockquote> 172 <h4 class="mansect"><a name="tag_20_02_17" id="tag_20_02_17"></a>EXAMPLES</h4> 173 <blockquote> 174 <ol> 175 <li> 176 <p>Create a short alias for a commonly used <a href="../utilities/ls.html"><i>ls</i></a> command:</p> 177 <pre> 178 <tt>alias lf="ls -CF" 179 </tt></pre></li> 180 <li> 181 <p>Create a simple "redo" command to repeat previous entries in the command history file:</p> 182 <pre> 183 <tt>alias r='fc -s' 184 </tt></pre></li> 185 <li> 186 <p>Use 1K units for <a href="../utilities/du.html"><i>du</i></a>:</p> 187 <pre> 188 <tt>alias du=du\ -k 189 </tt></pre></li> 190 <li> 191 <p>Set up <a href="../utilities/nohup.html"><i>nohup</i></a> so that it can deal with an argument that is itself an alias name:</p> 192 <pre> 193 <tt>alias nohup="nohup " 194 </tt></pre></li> 195 <li> 196 <p>Add the <b>-F</b> option to interactive uses of <a href="../utilities/ls.html"><i>ls</i></a>, even when executed as 197 <tt>xargs ls</tt> or <tt>xargs -0 ls</tt>:</p> 198 <pre> 199 <tt>alias ls='ls -F' 200 alias xargs='xargs ' 201 alias -- -0='-0 ' 202 find . [...] -print | xargs ls # breaks on filenames with \n 203 # (two aliases expanded) 204 find . [...] -print0 | xargs -0 ls # minimizes \n issues (three 205 # aliases expanded) 206 </tt></pre></li> 207 </ol> 208 </blockquote> 209 <h4 class="mansect"><a name="tag_20_02_18" id="tag_20_02_18"></a>RATIONALE</h4> 210 <blockquote> 211 <p>The <i>alias</i> description is based on historical KornShell implementations. Known differences exist between that and the C 212 shell. The KornShell version was adopted to be consistent with all the other KornShell features in this volume of POSIX.1-2024, 213 such as command line editing.</p> 214 <p>Since <i>alias</i> affects the current shell execution environment, it is generally provided as a shell regular built-in.</p> 215 <p>Historical versions of the KornShell have allowed aliases to be exported to scripts that are invoked by the same shell. This is 216 triggered by the <i>alias</i> <b>-x</b> flag; it is allowed by this volume of POSIX.1-2024 only when an explicit extension such as 217 <b>-x</b> is used. The standard developers considered that aliases were of use primarily to interactive users and that they should 218 normally not affect shell scripts called by those users; functions are available to such scripts.</p> 219 <p>Historical versions of the KornShell had not written aliases in a quoted manner suitable for reentry to the shell, but this 220 volume of POSIX.1-2024 has made this a requirement for all similar output. Therefore, consistency was chosen over this detail of 221 historical practice.</p> 222 </blockquote> 223 <h4 class="mansect"><a name="tag_20_02_19" id="tag_20_02_19"></a>FUTURE DIRECTIONS</h4> 224 <blockquote> 225 <p>None.</p> 226 </blockquote> 227 <h4 class="mansect"><a name="tag_20_02_20" id="tag_20_02_20"></a>SEE ALSO</h4> 228 <blockquote> 229 <p><a href="../utilities/V3_chap02.html#tag_19_09_05"><i>2.9.5 Function Definition Command</i></a></p> 230 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a></p> 231 </blockquote> 232 <h4 class="mansect"><a name="tag_20_02_21" id="tag_20_02_21"></a>CHANGE HISTORY</h4> 233 <blockquote> 234 <p>First released in Issue 4.</p> 235 </blockquote> 236 <h4 class="mansect"><a name="tag_20_02_22" id="tag_20_02_22"></a>Issue 6</h4> 237 <blockquote> 238 <p>This utility is marked as part of the User Portability Utilities option.</p> 239 <p>The APPLICATION USAGE section is added.</p> 240 </blockquote> 241 <h4 class="mansect"><a name="tag_20_02_23" id="tag_20_02_23"></a>Issue 7</h4> 242 <blockquote> 243 <p>The <i>alias</i> utility is moved from the User Portability Utilities option to the Base. User Portability Utilities is now an 244 option for interactive utilities.</p> 245 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p> 246 <p>The first example is changed to remove the creation of an alias for a standard utility that alters its behavior to be 247 non-conforming.</p> 248 </blockquote> 249 <h4 class="mansect"><a name="tag_20_02_24" id="tag_20_02_24"></a>Issue 8</h4> 250 <blockquote> 251 <p>Austin Group Defect 854 is applied, adding a note to the APPLICATION USAGE section that this utility is required to be 252 intrinsic.</p> 253 <p>Austin Group Defect 953 is applied, clarifying that the details of how alias replacement is performed are in the 254 cross-referenced section ( <a href="../utilities/V3_chap02.html#tag_19_03_01"><i>2.3.1 Alias Substitution</i></a> ) and updating 255 the APPLICATION USAGE section.</p> 256 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 257 <p>Austin Group Defect 1630 is applied, adding a new item in EXAMPLES.</p> 258 </blockquote> 259 <div class="box"><em>End of informative text.</em></div> 260 <hr> 261 <p> </p> 262 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 263 <hr size="2" noshade> 264 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 265 POSIX™ is a Trademark of The IEEE.<br> 266 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 267 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 268 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 269 ]</font></center> 270 <hr size="2" noshade> 271 <div class="NAVHEADER"> 272 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 273 <tr class="nav"> 274 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/admin.html" accesskey="P"><<< 275 Previous</a></td> 276 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 277 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/ar.html" accesskey="N">Next >>></a></td> 278 </tr> 279 </table> 280 <hr align="left" width="100%"></div> 281 </body> 282 </html>