Skip to content
xcu_chap02.html 127 KiB
Newer Older
Seblu's avatar
Seblu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>


<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="xcu_chap02_files/style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2004 IEEE and The Open Group, All Rights Reserved --><title>Shell Command Language</title></head><body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="xcu_chap02_files/codes.js">
</script>

<basefont size="3"> <!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1, 2004 Edition<br>
Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center>

<!--header end-->
<hr noshade="noshade" size="2">
<h2><a name="tag_02">  2. </a>Shell Command Language</h2>

<p>This chapter contains the definition of the Shell Command Language.</p>

<h3><a name="tag_02_01">   2.1 </a>Shell Introduction</h3>

<p>The shell is a command language interpreter. This chapter describes the syntax of that command language as it is used by the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html"><i>sh</i></a> utility and the <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><i>system</i>()</a> and <a href="http://www.opengroup.org/onlinepubs/009695399/functions/popen.html"><i>popen</i>()</a> functions defined in the System Interfaces volume of
IEEE&nbsp;Std&nbsp;1003.1-2001.</p>

<p>The shell operates according to the following general overview of operations. The specific details are included in the cited
sections of this chapter.</p>

<ol>
<li>
<p>The shell reads its input from a file (see <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html"><i>sh</i></a>), from the <b>-c</b> option or from the
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><i>system</i>()</a> and <a href="http://www.opengroup.org/onlinepubs/009695399/functions/popen.html"><i>popen</i>()</a> functions defined
in the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001. If the first line of a file of shell commands starts with the
characters <tt>"#!"</tt>, the results are unspecified.</p>
</li>

<li>
<p>The shell breaks the input into tokens: words and operators; see <a href="#tag_02_03">Token Recognition</a>.</p>
</li>

<li>
<p>The shell parses the input into simple commands (see <a href="#tag_02_09_01">Simple Commands</a>) and compound commands (see <a href="#tag_02_09_04">Compound Commands</a>).</p>
</li>

<li>
<p>The shell performs various expansions (separately) on different parts of each command, resulting in a list of pathnames and
fields to be treated as a command and arguments; see <a href="#tag_02_06">Word Expansions</a>.</p>
</li>

<li>
<p>The shell performs redirection (see <a href="#tag_02_07">Redirection</a>) and removes redirection operators and their operands
from the parameter list.</p>
</li>

<li>
<p>The shell executes a function (see <a href="#tag_02_09_05">Function Definition Command</a>), built-in (see <a href="#tag_02_14">Special Built-In Utilities</a>), executable file, or script, giving the names of the arguments as positional
parameters numbered 1 to <i>n</i>, and the name of the command (or in the case of a function within a script, the name of the
script) as the positional parameter numbered 0 (see <a href="#tag_02_09_01_01">Command Search and Execution</a>).</p>
</li>

<li>
<p>The shell optionally waits for the command to complete and collects the exit status (see <a href="#tag_02_08_02">Exit Status for
Commands</a>).</p>
</li>
</ol>

<h3><a name="tag_02_02">   2.2 </a>Quoting</h3>

<p>Quoting is used to remove the special meaning of certain characters
or words to the shell. Quoting can be used to preserve the
literal meaning of the special characters in the next paragraph,
prevent reserved words from being recognized as such, and prevent
parameter expansion and command substitution within here-document
processing (see <a href="#tag_02_07_04">Here-Document</a>).</p>

<p>The application shall quote the following characters if they are to represent themselves:</p>

<blockquote>
<pre><tt>|  &amp;  ;  &lt;  &gt;  (  )  $  `  \  "  '  &lt;space&gt;  &lt;tab&gt;  &lt;newline&gt;
</tt>
</pre>
</blockquote>

<p>and the following may need to be quoted under certain circumstances. That is, these characters may be special depending on
conditions described elsewhere in this volume of IEEE&nbsp;Std&nbsp;1003.1-2001:</p>

<blockquote>
<pre><tt>*   ?   [   #   &#732;   =   %
</tt>
</pre>
</blockquote>

<p>The various quoting mechanisms are the escape character, single-quotes, and double-quotes. The here-document represents another
form of quoting; see <a href="#tag_02_07_04">Here-Document</a>.</p>

<h4><a name="tag_02_02_01">  2.2.1 </a>Escape Character (Backslash)</h4>

<p>A backslash that is not quoted shall preserve the literal value of
the following character, with the exception of a
&lt;newline&gt;. If a &lt;newline&gt; follows the backslash, the shell
shall interpret this as line continuation. The backslash and
&lt;newline&gt;s shall be removed before splitting the input into
tokens. Since the escaped &lt;newline&gt; is removed entirely
from the input and is not replaced by any white space, it cannot serve
as a token separator.</p>

<h4><a name="tag_02_02_02">  2.2.2 </a>Single-Quotes</h4>

<p>Enclosing characters in single-quotes ( <tt>''</tt> ) shall preserve the literal value of each character within the
single-quotes. A single-quote cannot occur within single-quotes.</p>

<h4><a name="tag_02_02_03">  2.2.3 </a>Double-Quotes</h4>

<p>Enclosing characters in double-quotes ( <tt>""</tt> ) shall preserve the literal value of all characters within the
double-quotes, with the exception of the characters dollar sign, backquote, and backslash, as follows:</p>

<dl compact="compact">
<dt><tt>$</tt></dt>

<dd>The dollar sign shall retain its special meaning introducing parameter expansion (see <a href="#tag_02_06_02">Parameter
Expansion</a>), a form of command substitution (see <a href="#tag_02_06_03">Command Substitution</a>), and arithmetic expansion
(see <a href="#tag_02_06_04">Arithmetic Expansion</a>). 

<p>The input characters within the quoted string that are also enclosed between <tt>"$("</tt> and the matching <tt>')'</tt> shall
not be affected by the double-quotes, but rather shall define that command whose output replaces the <tt>"$(...)"</tt> when the
word is expanded. The tokenizing rules in <a href="#tag_02_03">Token Recognition</a> , not including the alias substitutions in <a href="#tag_02_03_01">Alias Substitution</a> , shall be applied recursively to find the matching <tt>')'</tt>.</p>

<p>Within the string of characters from an enclosed <tt>"${"</tt> to the matching <tt>'}'</tt>, an even number of unescaped
double-quotes or single-quotes, if any, shall occur. A preceding backslash character shall be used to escape a literal <tt>'{'</tt>
or <tt>'}'</tt>. The rule in <a href="#tag_02_06_02">Parameter Expansion</a> shall be used to determine the matching <tt>'}'</tt>
.</p>
</dd>

<dt><tt>`</tt></dt>

<dd>The backquote shall retain its special meaning introducing the other form of command substitution (see <a href="#tag_02_06_03">Command Substitution</a>). The portion of the quoted string from the initial backquote and the characters up to
the next backquote that is not preceded by a backslash, having escape characters removed, defines that command whose output
replaces <tt>"`...`"</tt> when the word is expanded. Either of the following cases produces undefined results: 

<ul>
<li>
<p>A single-quoted or double-quoted string that begins, but does not end, within the <tt>"`...`"</tt> sequence</p>
</li>

<li>
<p>A <tt>"`...`"</tt> sequence that begins, but does not end, within the same double-quoted string</p>
</li>
</ul>
</dd>

<dt><tt>\</tt></dt>

<dd>The backslash shall retain its special meaning as an escape character (see <a href="#tag_02_02_01">Escape Character
(Backslash)</a>) only when followed by one of the following characters when considered special: 

<blockquote>
<pre><tt>$   `   "   \   &lt;newline&gt;
</tt>
</pre>
</blockquote>
</dd>
</dl>

<p>The application shall ensure that a double-quote is preceded by a backslash to be included within double-quotes. The parameter
<tt>'@'</tt> has special meaning inside double-quotes and is described in <a href="#tag_02_05_02">Special Parameters</a>.</p>

<h3><a name="tag_02_03">   2.3 </a>Token Recognition</h3>

<p>The shell shall read its input in terms of lines from a file, from a terminal in the case of an interactive shell, or from a
string in the case of <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html"><i>sh</i></a> <b>-c</b> or <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><i>system</i>()</a>. The input lines can be of unlimited length. These lines shall be parsed using two
major modes: ordinary token recognition and processing of here-documents.</p>

<p>When an <b>io_here</b> token has been recognized by the grammar (see <a href="#tag_02_10">Shell Grammar</a>), one or more of
the subsequent lines immediately following the next <b>NEWLINE</b> token form the body of one or more here-documents and shall be
parsed according to the rules of <a href="#tag_02_07_04">Here-Document</a>.</p>

<p>When it is not processing an <b>io_here</b>, the shell shall break its input into tokens by applying the first applicable rule
below to the next character in its input. The token shall be from the current position in the input until a token is delimited
according to one of the rules below; the characters forming the token are exactly those in the input, including any quoting
characters. If it is indicated that a token is delimited, and no characters have been included in a token, processing shall
continue until an actual token is delimited.</p>

<ol>
<li>
<p>If the end of input is recognized, the current token shall be delimited. If there is no current token, the end-of-input
indicator shall be returned as the token.</p>
</li>

<li>
<p>If the previous character was used as part of an operator and the current character is not quoted and can be used with the
current characters to form an operator, it shall be used as part of that (operator) token.</p>
</li>

<li>
<p>If the previous character was used as part of an operator and the current character cannot be used with the current characters
to form an operator, the operator containing the previous character shall be delimited.</p>
</li>

<li>
<p>If the current character is backslash, single-quote, or double-quote ( <tt>'\'</tt>, <tt>'"</tt>, or <tt>' )'</tt> and it is
not quoted, it shall affect quoting for subsequent characters up to the end of the quoted text. The rules for quoting are as
described in <a href="#tag_02_02">Quoting</a>. During token recognition no substitutions shall be actually performed, and the
result token shall contain exactly the characters that appear in the input (except for &lt;newline&gt; joining), unmodified,
including any embedded or enclosing quotes or substitution operators, between the quote mark and the end of the quoted text. The
token shall not be delimited by the end of the quoted field.</p>
</li>

<li>
<p>If the current character is an unquoted <tt>'$'</tt> or <tt>'`'</tt>, the shell shall identify the start of any candidates for
parameter expansion ( <a href="#tag_02_06_02">Parameter Expansion</a>), command substitution ( <a href="#tag_02_06_03">Command
Substitution</a>), or arithmetic expansion ( <a href="#tag_02_06_04">Arithmetic Expansion</a>) from their introductory unquoted
character sequences: <tt>'$'</tt> or <tt>"${"</tt>, <tt>"$("</tt> or <tt>'`'</tt>, and <tt>"$(("</tt>,
respectively. The shell
shall read sufficient input to determine the end of the unit to be
expanded (as explained in the cited sections). While processing
the characters, if instances of expansions or quoting are found nested
within the substitution, the shell shall recursively process
them in the manner specified for the construct that is found. The
characters found from the beginning of the substitution to its
end, allowing for any recursion necessary to recognize embedded
constructs, shall be included unmodified in the result token,
including any embedded or enclosing substitution operators or quotes.
The token shall not be delimited by the end of the
substitution.</p>
</li>

<li>
<p>If the current character is not quoted and can be used as the first character of a new operator, the current token (if any)
shall be delimited. The current character shall be used as the beginning of the next (operator) token.</p>
</li>

<li>
<p>If the current character is an unquoted &lt;newline&gt;, the current token shall be delimited.</p>
</li>

<li>
<p>If the current character is an unquoted &lt;blank&gt;, any token containing the previous character is delimited and the current
character shall be discarded.</p>
</li>

<li>
<p>If the previous character was part of a word, the current character shall be appended to that word.</p>
</li>

<li>
<p>If the current character is a <tt>'#'</tt>, it and all subsequent characters up to, but excluding, the next &lt;newline&gt;
shall be discarded as a comment. The &lt;newline&gt; that ends the line is not considered part of the comment.</p>
</li>

<li>
<p>The current character is used as the start of a new word.</p>
</li>
</ol>

<p>Once a token is delimited, it is categorized as required by the grammar in <a href="#tag_02_10">Shell Grammar</a>.</p>

<h4><a name="tag_02_03_01">  2.3.1 </a>Alias Substitution</h4>

<p><sup>[<a href="javascript:open_code('UP XSI')">UP XSI</a>]</sup> <img src="xcu_chap02_files/opt-start.gif" alt="[Option Start]" border="0"> The processing of aliases shall be supported on all XSI-conformant systems or if the system supports the User Portability
Utilities option (and the rest of this section is not further marked for these options). <img src="xcu_chap02_files/opt-end.gif" alt="[Option End]" border="0"></p>

<p>After a token has been delimited, but before applying the grammatical rules in <a href="#tag_02_10">Shell Grammar</a>
, a
resulting word that is identified to be the command name word of a
simple command shall be examined to determine whether it is an
unquoted, valid alias name. However, reserved words in correct
grammatical context shall not be candidates for alias substitution.
A valid alias name (see the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_10">Section 3.10, Alias Name</a>) shall be one that has been defined by the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/alias.html"><i>alias</i></a> utility and not subsequently undefined using <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/unalias.html"><i>unalias</i></a>. Implementations also may provide predefined valid aliases that are in effect when
the shell is invoked. To prevent infinite loops in recursive aliasing, if the shell is not currently processing an alias of the
same name, the word shall be replaced by the value of the alias; otherwise, it shall not be replaced.</p>

<p>If the value of the alias replacing the word ends in a &lt;blank&gt;, the shell shall check the next command word for alias
substitution; this process shall continue until a word is found that is not a valid alias or an alias value does not end in a
&lt;blank&gt;.</p>

<p>When used as specified by this volume of IEEE&nbsp;Std&nbsp;1003.1-2001, alias definitions shall not be inherited by separate
invocations of the shell or by the utility execution environments invoked by the shell; see <a href="#tag_02_12">Shell Execution
Environment</a>.</p>

<h3><a name="tag_02_04">   2.4 </a>Reserved Words</h3>

<p>Reserved words are words that have special meaning to the shell; see <a href="#tag_02_09">Shell Commands</a>. The following
words shall be recognized as reserved words:</p>

<blockquote>
<table cellpadding="3">
<tbody><tr valign="top">
<td align="left">
<p class="tent"><b><br>
!<br>
 {<br>
 }<br>
 case<br>
</b></p>
</td>
<td align="left">
<p class="tent"><b><br>
do<br>
 done<br>
 elif<br>
 else<br>
</b></p>
</td>
<td align="left">
<p class="tent"><b><br>
esac<br>
 fi<br>
 for<br>
 if<br>
</b></p>
</td>
<td align="left">
<p class="tent"><b><br>
in<br>
 then<br>
 until<br>
 while<br>
</b></p>
</td>
</tr>
</tbody></table>
</blockquote>

<p>This recognition shall only occur when none of the characters is quoted and when the word is used as:</p>

<ul>
<li>
<p>The first word of a command</p>
</li>

<li>
<p>The first word following one of the reserved words other than <b>case</b>, <b>for</b>, or <b>in</b></p>
</li>

<li>
<p>The third word in a <b>case</b> command (only <b>in</b> is valid in this case)</p>
</li>

<li>
<p>The third word in a <b>for</b> command (only <b>in</b> and <b>do</b> are valid in this case)</p>
</li>
</ul>

<p>See the grammar in <a href="#tag_02_10">Shell Grammar</a>.</p>

<p>The following words may be recognized as reserved words on some implementations (when none of the characters are quoted),
causing unspecified results:</p>

<blockquote>
<table cellpadding="3">
<tbody><tr valign="top">
<td align="left">
<p class="tent"><b>[[</b></p>
</td>
<td align="left">
<p class="tent"><b>]]</b></p>
</td>
<td align="left">
<p class="tent"><b>function</b></p>
</td>
<td align="left">
<p class="tent"><b>select</b></p>
</td>
</tr>
</tbody></table>
</blockquote>

<p>Words that are the concatenation of a name and a colon ( <tt>':'</tt> ) are reserved; their use produces unspecified
results.</p>

<h3><a name="tag_02_05">   2.5 </a>Parameters and Variables</h3>

<p>A parameter can be denoted by a name, a number, or one of the special characters listed in <a href="#tag_02_05_02">Special
Parameters</a>. A variable is a parameter denoted by a name.</p>

<p>A parameter is set if it has an assigned value (null is a valid value). Once a variable is set, it can only be unset by using
the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/unset.html"><i>unset</i></a> special built-in command.</p>

<h4><a name="tag_02_05_01">  2.5.1 </a>Positional Parameters</h4>

<p>A positional parameter is a parameter denoted by the decimal value
represented by one or more digits, other than the single
digit 0. The digits denoting the positional parameters shall always be
interpreted as a decimal value, even if there is a leading
zero. When a positional parameter with more than one digit is
specified, the application shall enclose the digits in braces (see <a href="#tag_02_06_02">Parameter Expansion</a>). Positional parameters are initially assigned when the shell is invoked (see <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html"><i>sh</i></a>), temporarily replaced when a shell function is invoked (see <a href="#tag_02_09_05">Function Definition Command</a>), and can be reassigned with the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/set.html"><i>set</i></a> special built-in
command.</p>

<h4><a name="tag_02_05_02">  2.5.2 </a>Special Parameters</h4>

<p>Listed below are the special parameters and the values to which they shall expand. Only the values of the special parameters are
listed; see <a href="#tag_02_06">Word Expansions</a> for a detailed summary of all the stages involved in expanding words.</p>

<dl compact="compact">
<dt><tt>@</tt></dt>

<dd>Expands to the positional parameters, starting from one. When the expansion occurs within double-quotes, and where field
splitting (see <a href="#tag_02_06_05">Field Splitting</a>)
is performed, each positional parameter shall expand as a separate
field, with the provision that the expansion of the first parameter
shall still be joined with the beginning part of the original
word (assuming that the expanded parameter was embedded within a word),
and the expansion of the last parameter shall still be
joined with the last part of the original word. If there are no
positional parameters, the expansion of <tt>'@'</tt> shall generate
zero fields, even when <tt>'@'</tt> is double-quoted.</dd>

<dt><tt>*</tt></dt>

<dd>Expands to the positional parameters, starting from one. When the expansion occurs within a double-quoted string (see <a href="#tag_02_02_03">Double-Quotes</a>), it shall expand to a single field with the value of each parameter separated by the first
character of the <i>IFS</i> variable, or by a &lt;space&gt; if <i>IFS</i> is unset. If <i>IFS</i> is set to a null string, this is
not equivalent to unsetting it; its first character does not exist, so the parameter values are concatenated.</dd>

<dt><tt>#</tt></dt>

<dd>Expands to the decimal number of positional parameters. The command name (parameter 0) shall not be counted in the number given
by <tt>'#'</tt> because it is a special parameter, not a positional parameter.</dd>

<dt><tt>?</tt></dt>

<dd>Expands to the decimal exit status of the most recent pipeline (see <a href="#tag_02_09_02">Pipelines</a>).</dd>

<dt><tt>-</tt></dt>

<dd>(Hyphen.) Expands to the current option flags (the single-letter option names concatenated into a string) as specified on
invocation, by the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/set.html"><i>set</i></a> special built-in command, or implicitly by the shell.</dd>

<dt><tt>$</tt></dt>

<dd>Expands to the decimal process ID of the invoked shell. In a subshell (see <a href="#tag_02_12">Shell Execution Environment</a>
), <tt>'$'</tt> shall expand to the same value as that of the current shell.</dd>

<dt><tt>!</tt></dt>

<dd>Expands to the decimal process ID of the most recent background command (see <a href="#tag_02_09_03">Lists</a>) executed from
the current shell. (For example, background commands executed from subshells do not affect the value of <tt>"$!"</tt> in the
current shell environment.) For a pipeline, the process ID is that of the last command in the pipeline.</dd>

<dt>0</dt>

<dd>(Zero.) Expands to the name of the shell or shell script. See <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html"><i>sh</i></a> for a detailed description of how
this name is derived.</dd>
</dl>

<p>See the description of the <i>IFS</i> variable in <a href="#tag_02_05_03">Shell Variables</a>.</p>

<h4><a name="tag_02_05_03">  2.5.3 </a>Shell Variables</h4>

<p>Variables shall be initialized from the environment (as defined by the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a> and the <i>exec</i>
function in the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001) and can be given new values with variable assignment
commands. If a variable is initialized from the environment, it shall be marked for export immediately; see the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/export.html"><i>export</i></a> special built-in. New variables can be defined and initialized with variable assignments, with the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/read.html"><i>read</i></a> or <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/getopts.html"><i>getopts</i></a> utilities, with the
<i>name</i> parameter in a <b>for</b> loop, with the ${ <i>name</i>= <i>word</i>} expansion, or with other mechanisms provided as
implementation extensions.</p>

<p>The following variables shall affect the execution of the shell:</p>

<dl compact="compact">
<dt><i>ENV</i></dt>

<dd><sup>[<a href="javascript:open_code('UP XSI')">UP XSI</a>]</sup> <img src="xcu_chap02_files/opt-start.gif" alt="[Option Start]" border="0"> The processing of the <i>ENV</i> shell variable shall be supported on all XSI-conformant systems or if the system
supports the User Portability Utilities option. <img src="xcu_chap02_files/opt-end.gif" alt="[Option End]" border="0"> 

<p>This variable, when and only when an interactive shell is invoked, shall be subjected to parameter expansion (see <a href="#tag_02_06_02">Parameter Expansion</a>) by the shell and the resulting value shall be used as a pathname of a file containing
shell commands to execute in the current environment. The file need not be executable. If the expanded value of <i>ENV</i> is not
an absolute pathname, the results are unspecified. <i>ENV</i> shall be ignored if the user's real and effective user IDs or real
and effective group IDs are different.</p>
</dd>

<dt><i>HOME</i></dt>

<dd>The pathname of the user's home directory. The contents of <i>HOME</i> are used in tilde expansion (see <a href="#tag_02_06_01">Tilde Expansion</a>).</dd>

<dt><i>IFS</i></dt>

<dd>(Input Field Separators.) A string treated as a list of characters that is used for field splitting and to split lines into
fields with the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/read.html"><i>read</i></a> command. If <i>IFS</i> is not set, the shell shall behave as if
the value of <i>IFS</i> is &lt;space&gt;, &lt;tab&gt;, and &lt;newline&gt;; see <a href="#tag_02_06_05">Field Splitting</a>.
Implementations may ignore the value of <i>IFS</i> in the environment at the time the shell is invoked, treating <i>IFS</i> as if
it were not set.</dd>

<dt><i>LANG</i></dt>

<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>

<dt><i>LC_ALL</i></dt>

<dd>The value of this variable overrides the <i>LC_*</i> variables and <i>LANG ,</i> as described in the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>.</dd>

<dt><i>LC_COLLATE</i></dt>

<dd>Determine the behavior of range expressions, equivalence classes, and multi-character collating elements within pattern
matching.</dd>

<dt><i>LC_CTYPE</i></dt>

<dd>Determine the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to
multi-byte characters), which characters are defined as letters (character class <b>alpha</b>) and &lt;blank&gt;s (character class
<b>blank</b>), and the behavior of character classes within pattern matching. Changing the value of <i>LC_CTYPE</i>
after the shell
has started shall not affect the lexical processing of shell commands
in the current shell execution environment or its subshells.
Invoking a shell script or performing <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/exec.html"><i>exec</i></a> <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html"><i>sh</i></a> subjects the new
shell to the changes in <i>LC_CTYPE .</i></dd>

<dt><i>LC_MESSAGES</i></dt>

<dd>Determine the language in which messages should be written.</dd>

<dt><i>LINENO</i></dt>

<dd>Set by the shell to a decimal number representing the current sequential line number (numbered starting with 1) within a script
or function before it executes each command. If the user unsets or resets <i>LINENO ,</i> the variable may lose its special meaning
for the life of the shell. If the shell is not currently executing a script or function, the value of <i>LINENO</i> is unspecified.
This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of the variable only for systems supporting the User
Portability Utilities option.</dd>

<dt><i>NLSPATH</i></dt>

<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="xcu_chap02_files/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="xcu_chap02_files/opt-end.gif" alt="[Option End]" border="0"></dd>

<dt><i>PATH</i></dt>

<dd>A string formatted as described in the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>, used to effect command interpretation; see <a href="#tag_02_09_01_01">Command Search and Execution</a>.</dd>

<dt><i>PPID</i></dt>

<dd>Set by the shell to the decimal process ID of the process that invoked this shell. In a subshell (see <a href="#tag_02_12">Shell Execution Environment</a>), <i>PPID</i> shall be set to the same value as that of the parent of the current
shell. For example, <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html"><i>echo</i></a> $ <i>PPID</i> and ( <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html"><i>echo</i></a> $ <i>PPID )</i> would produce the same value. This volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of the variable only for systems supporting the User Portability Utilities
option.</dd>

<dt><i>PS1</i></dt>

<dd>Each time an interactive shell is ready to read a command, the value of this variable shall be subjected to parameter expansion
and written to standard error. The default value shall be <tt>"$&nbsp;"</tt>.
For users who have specific additional
implementation-defined privileges, the default may be another,
implementation-defined value. The shell shall replace each instance
of the character <tt>'!'</tt> in <i>PS1</i> with the history file number of the next command to be typed. Escaping the <tt>'!'</tt>
with another <tt>'!'</tt> (that is, <tt>"!!"</tt> ) shall place the literal character <tt>'!'</tt> in the prompt. This volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of the variable only for systems supporting the User Portability Utilities
option.</dd>

<dt><i>PS2</i></dt>

<dd>Each time the user enters a &lt;newline&gt; prior to completing a command line in an interactive shell, the value of this
variable shall be subjected to parameter expansion and written to standard error. The default value is <tt>"&gt;&nbsp;"</tt>. This
volume of IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of the variable only for systems supporting the User Portability
Utilities option.</dd>

<dt><i>PS4</i></dt>

<dd>When an execution trace ( <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/set.html"><i>set</i></a> <b>-x</b>) is being performed in an interactive shell, before each line
in the execution trace, the value of this variable shall be subjected to parameter expansion and written to standard error. The
default value is <tt>"+&nbsp;"</tt>. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of the variable only for
systems supporting the User Portability Utilities option.</dd>

<dt><i>PWD</i></dt>

<dd>Set by the shell to be an absolute pathname of the current working
directory, containing no components of type symbolic link,
no components that are dot, and no components that are dot-dot when the
shell is initialized. If an application sets or unsets the
value of <i>PWD ,</i> the behaviors of the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/cd.html"><i>cd</i></a> and <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/pwd.html"><i>pwd</i></a> utilities are unspecified.</dd>
</dl>

<h3><a name="tag_02_06">   2.6 </a>Word Expansions</h3>

<p>This section describes the various expansions that are performed on words. Not all expansions are performed on every word, as
explained in the following sections.</p>

<p>Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote removals that occur within a
single word expand to a single field. It is only field splitting or pathname expansion that can create multiple fields from a
single word. The single exception to this rule is the expansion of the special parameter <tt>'@'</tt> within double-quotes, as
described in <a href="#tag_02_05_02">Special Parameters</a>.</p>

<p>The order of word expansion shall be as follows:</p>

<ol>
<li>
<p>Tilde expansion (see <a href="#tag_02_06_01">Tilde Expansion</a>), parameter expansion (see <a href="#tag_02_06_02">Parameter
Expansion</a>), command substitution (see <a href="#tag_02_06_03">Command Substitution</a>), and arithmetic expansion (see <a href="#tag_02_06_04">Arithmetic Expansion</a>) shall be performed, beginning to end. See item 5 in <a href="#tag_02_03">Token
Recognition</a>.</p>
</li>

<li>
<p>Field splitting (see <a href="#tag_02_06_05">Field Splitting</a>) shall be performed on the portions of the fields generated by
step 1, unless <i>IFS</i> is null.</p>
</li>

<li>
<p>Pathname expansion (see <a href="#tag_02_06_06">Pathname Expansion</a>) shall be performed, unless <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/set.html"><i>set</i></a> <b>-f</b> is in effect.</p>
</li>

<li>
<p>Quote removal (see <a href="#tag_02_06_07">Quote Removal</a>) shall always be performed last.</p>
</li>
</ol>

<p>The expansions described in this section shall occur in the same shell environment as that in which the command is executed.</p>

<p>If the complete expansion appropriate for a word results in an empty field, that empty field shall be deleted from the list of
fields that form the completely expanded command, unless the original word contained single-quote or double-quote characters.</p>

<p>The <tt>'$'</tt> character is used to introduce parameter expansion, command substitution, or arithmetic evaluation. If an
unquoted <tt>'$'</tt> is followed by a character that is either not numeric, the name of one of the special parameters (see <a href="#tag_02_05_02">Special Parameters</a>), a valid first character of a variable name, a left curly brace ( <tt>'{'</tt> ) or a
left parenthesis, the result is unspecified.</p>

<h4><a name="tag_02_06_01">  2.6.1 </a>Tilde Expansion</h4>

<p>A "tilde-prefix" consists of an unquoted tilde character at the
beginning of a word, followed by all of the characters
preceding the first unquoted slash in the word, or all the characters
in the word if there is no slash. In an assignment (see the
Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_21">Section 4.21, Variable
Assignment</a>),
multiple tilde-prefixes can be used: at the beginning of the word (that
is, following the equal sign of the
assignment), following any unquoted colon, or both. A tilde-prefix in
an assignment is terminated by the first unquoted colon or
slash. If none of the characters in the tilde-prefix are quoted, the
characters in the tilde-prefix following the tilde are treated
as a possible login name from the user database. A portable login name
cannot contain characters outside the set given in the
description of the <i>LOGNAME</i> environment variable in the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html#tag_08_03">Section 8.3, Other Environment Variables</a>. If the login name is null (that is, the
tilde-prefix contains only the tilde), the tilde-prefix is replaced by the value of the variable <i>HOME .</i> If <i>HOME</i> is
unset, the results are unspecified. Otherwise, the tilde-prefix shall be replaced by a pathname of the initial working directory
associated with the login name obtained using the <a href="http://www.opengroup.org/onlinepubs/009695399/functions/getpwnam.html"><i>getpwnam</i>()</a> function as defined in
the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001. If the system does not recognize the login name, the results are
undefined.</p>

<h4><a name="tag_02_06_02">  2.6.2 </a>Parameter Expansion</h4>

<p>The format for parameter expansion is as follows:</p>

<blockquote>
<pre><tt>${</tt><i>expression</i><tt>}
</tt>
</pre>
</blockquote>

<p>where <i>expression</i> consists of all characters until the matching <tt>'}'</tt>. Any <tt>'}'</tt>
escaped by a backslash or
within a quoted string, and characters in embedded arithmetic
expansions, command substitutions, and variable expansions, shall not
be examined in determining the matching <tt>'}'</tt>.</p>

<p>The simplest form for parameter expansion is:</p>

<blockquote>
<pre><tt>${</tt><i>parameter</i><tt>}
</tt>
</pre>
</blockquote>

<p>The value, if any, of <i>parameter</i> shall be substituted.</p>

<p>The parameter name or symbol can be enclosed in braces, which are optional except for positional parameters with more than one
digit or when <i>parameter</i> is followed by a character that could be interpreted as part of the name. The matching closing brace
shall be determined by counting brace levels, skipping over enclosed quoted strings, and command substitutions.</p>

<p>If the parameter name or symbol is not enclosed in braces, the expansion shall use the longest valid name (see the Base
Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_230">Section 3.230, Name</a>),
whether or not the symbol represented by that name exists.</p>

<p>If a parameter expansion occurs inside double-quotes:</p>

<ul>
<li>
<p>Pathname expansion shall not be performed on the results of the expansion.</p>
</li>

<li>
<p>Field splitting shall not be performed on the results of the expansion, with the exception of <tt>'@'</tt> ; see <a href="#tag_02_05_02">Special Parameters</a>.</p>
</li>
</ul>

<p>In addition, a parameter expansion can be modified by using one of the following formats. In each case that a value of
<i>word</i> is needed (based on the state of <i>parameter</i>, as described below), <i>word</i> shall be subjected to tilde
expansion, parameter expansion, command substitution, and arithmetic expansion. If <i>word</i> is not needed, it shall not be
expanded. The <tt>'}'</tt> character that delimits the following parameter expansion modifications shall be determined as described
previously in this section and in <a href="#tag_02_02_03">Double-Quotes</a>. (For example, ${ <b>foo-bar</b>} <b>xyz</b>} would
result in the expansion of <b>foo</b> followed by the string <b>xyz</b>} if <b>foo</b> is set, else the string <tt>"barxyz}"</tt>
).</p>

<dl compact="compact">
<dt>${<i>parameter</i>:-<i>word</i>}</dt>

<dd><b>Use Default Values</b>. If <i>parameter</i> is unset or null, the expansion of <i>word</i> shall be substituted; otherwise,
the value of <i>parameter</i> shall be substituted.</dd>

<dt>${<i>parameter</i>:=<i>word</i>}</dt>

<dd><b>Assign Default Values</b>. If <i>parameter</i> is unset or null, the expansion of <i>word</i> shall be assigned to
<i>parameter</i>. In all cases, the final value of <i>parameter</i> shall be substituted. Only variables, not positional parameters
or special parameters, can be assigned in this way.</dd>

<dt>${<i>parameter</i>:?<b>[</b><i>word</i><b>]</b>}</dt>

<dd><b>Indicate Error if Null or Unset</b>. If <i>parameter</i> is unset or null, the expansion of <i>word</i> (or a message
indicating it is unset if <i>word</i> is omitted) shall be written to standard error and the shell exits with a non-zero exit
status. Otherwise, the value of <i>parameter</i> shall be substituted. An interactive shell need not exit.</dd>

<dt>${<i>parameter</i>:+<i>word</i>}</dt>

<dd><b>Use Alternative Value</b>. If <i>parameter</i> is unset or null, null shall be substituted; otherwise, the expansion of
<i>word</i> shall be substituted.</dd>
</dl>

<p>In the parameter expansions shown previously, use of the colon in
the format shall result in a test for a parameter that is
unset or null; omission of the colon shall result in a test for a
parameter that is only unset. The following table summarizes the
effect of the colon:</p>

<center>
<table align="center" border="1" cellpadding="3">
<tbody><tr valign="top">
<th align="center">
<p class="tent"><i>&nbsp;</i></p>
</th>
<th align="center">
<p class="tent"><i>parameter</i></p>
</th>
<th align="center">
<p class="tent"><i>parameter</i></p>
</th>
<th align="center">
<p class="tent"><i>parameter</i></p>
</th>
</tr>

<tr valign="top">
<th align="center">
<p class="tent"><b>&nbsp;</b></p>
</th>
<th align="center">
<p class="tent"><b>Set and Not Null</b></p>
</th>
<th align="center">
<p class="tent"><b>Set But Null</b></p>
</th>
<th align="center">
<p class="tent"><b>Unset</b></p>
</th>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>:-</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>parameter</i></p>
</td>
<td align="left">
<p class="tent">substitute <i>word</i></p>
</td>
<td align="left">
<p class="tent">substitute <i>word</i></p>
</td>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>-</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>parameter</i></p>
</td>
<td align="left">
<p class="tent">substitute null</p>
</td>
<td align="left">
<p class="tent">substitute <i>word</i></p>
</td>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>:=</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>parameter</i></p>
</td>
<td align="left">
<p class="tent">assign <i>word</i></p>
</td>
<td align="left">
<p class="tent">assign <i>word</i></p>
</td>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>=</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>parameter</i></p>
</td>
<td align="left">
<p class="tent">substitute null</p>
</td>
<td align="left">
<p class="tent">assign <i>word</i></p>
</td>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>:?</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>parameter</i></p>
</td>
<td align="left">
<p class="tent">error, exit</p>
</td>
<td align="left">
<p class="tent">error, exit</p>
</td>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>?</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>parameter</i></p>
</td>
<td align="left">
<p class="tent">substitute null</p>
</td>
<td align="left">
<p class="tent">error, exit</p>
</td>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>:+</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>word</i></p>
</td>
<td align="left">
<p class="tent">substitute null</p>
</td>
<td align="left">
<p class="tent">substitute null</p>
</td>
</tr>

<tr valign="top">
<td align="left">
<p class="tent"><b>${</b><i>parameter</i><b>+</b><i>word</i><b>}</b></p>
</td>
<td align="left">
<p class="tent">substitute <i>word</i></p>
</td>
<td align="left">
<p class="tent">substitute <i>word</i></p>
</td>
<td align="left">
<p class="tent">substitute null</p>
</td>
</tr>
</tbody></table>
</center>

<p>In all cases shown with "substitute", the expression is replaced with the value shown. In all cases shown with "assign",
<i>parameter</i> is assigned that value, which also replaces the expression.</p>

<dl compact="compact">
<dt>${#<i>parameter</i>}</dt>

<dd><b>String Length</b>. The length in characters of the value of <i>parameter</i> shall be substituted. If <i>parameter</i> is
<tt>'*'</tt> or <tt>'@'</tt>, the result of the expansion is unspecified.</dd>
</dl>

<p>The following four varieties of parameter expansion provide for substring processing. In each case, pattern matching notation
(see <a href="#tag_02_13">Pattern Matching Notation</a>), rather than regular expression notation, shall be used to evaluate the
patterns. If <i>parameter</i> is <tt>'*'</tt> or <tt>'@'</tt>, the result of the expansion is unspecified. Enclosing the full
parameter expansion string in double-quotes shall not cause the following four varieties of pattern characters to be quoted,
whereas quoting characters within the braces shall have this effect.</p>

<dl compact="compact">
<dt>${<i>parameter</i>%<i>word</i>}</dt>

<dd><b>Remove Smallest Suffix Pattern</b>. The <i>word</i> shall be expanded to produce a pattern. The parameter expansion shall
then result in <i>parameter</i>, with the smallest portion of the suffix matched by the <i>pattern</i> deleted.</dd>

<dt>${<i>parameter</i>%%<i>word</i>}</dt>

<dd><b>Remove Largest Suffix Pattern</b>. The <i>word</i> shall be expanded to produce a pattern. The parameter expansion shall
then result in <i>parameter</i>, with the largest portion of the suffix matched by the <i>pattern</i> deleted.</dd>

<dt>${<i>parameter</i>#<i>word</i>}</dt>

<dd><b>Remove Smallest Prefix Pattern</b>. The <i>word</i> shall be expanded to produce a pattern. The parameter expansion shall
then result in <i>parameter</i>, with the smallest portion of the prefix matched by the <i>pattern</i> deleted.</dd>

<dt>${<i>parameter</i>##<i>word</i>}</dt>

<dd><b>Remove Largest Prefix Pattern</b>. The <i>word</i> shall be expanded to produce a pattern. The parameter expansion shall
then result in <i>parameter</i>, with the largest portion of the prefix matched by the <i>pattern</i> deleted.</dd>
</dl>

<hr>
<div class="box"><em>The following sections are informative.</em></div>

<h5><a name="tag_02_06_02_01"></a>Examples</h5>

<dl compact="compact">
<dt>${<i>parameter</i>:-<i>word</i>}</dt>

<dd>
In this example, <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/ls.html"><i>ls</i></a> is executed only if <i>x</i> is null or unset. (The $( <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/ls.html"><i>ls</i></a>) command substitution notation is explained in <a href="#tag_02_06_03">Command
Substitution</a>.) 

<blockquote>
<pre><tt>${x:-$(ls)}
</tt>
</pre>
</blockquote>
</dd>

<dt>${<i>parameter</i>:=<i>word</i>}</dt>

<dd>
<pre><tt>unset X
echo ${X:=abc}
</tt><b>abc</b>
</pre>
</dd>

<dt>${<i>parameter</i>:?<i>word</i>}</dt>

<dd>
<pre><tt>unset posix
echo ${posix:?}
</tt><b>sh: posix: parameter null or not set</b>
</pre>
</dd>

<dt>${<i>parameter</i>:+<i>word</i>}</dt>

<dd>
<pre><tt>set a b c
echo ${3:+posix}
</tt><b>posix</b>
</pre>
</dd>

<dt>${#<i>parameter</i>}</dt>

<dd>
<pre><tt>HOME=/usr/posix
echo ${#HOME}
</tt><b>10</b>
</pre>
</dd>

<dt>${<i>parameter</i>%<i>word</i>}</dt>

<dd>
<pre><tt>x=file.c
echo ${x%.c}.o
</tt><b>file.o</b>
</pre>
</dd>

<dt>${<i>parameter</i>%%<i>word</i>}</dt>

<dd>
<pre><tt>x=posix/src/std
echo ${x%%/*}
</tt><b>posix</b>
</pre>
</dd>

<dt>${<i>parameter</i>#<i>word</i>}</dt>

<dd>
<pre><tt>x=$HOME/src/cmd
echo ${x#$HOME}
</tt><b>/src/cmd</b>
</pre>
</dd>

<dt>${<i>parameter</i>##<i>word</i>}</dt>

<dd>
<pre><tt>x=/one/two/three