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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
|
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "SH" P 2003 POSIX
.\" sh
.SH NAME
sh \- shell, the standard command language interpreter
.SH SYNOPSIS
.LP
\fBsh\fP \fB[\fP\fB-abCefhimnuvx\fP\fB][\fP\fB-o\fP \fIoption\fP\fB][\fP\fB+abCefhimnuvx\fP\fB][\fP\fB+o\fP
\fIoption\fP\fB]
.br
\fP \fB\ \ \ \ \ \ \fP \fB[\fP\fIcommand_file\fP \fB[\fP\fIargument\fP\fB...\fP\fB]]\fP\fB
.br
.sp
sh -c\fP\fB[\fP\fB-abCefhimnuvx\fP\fB][\fP\fB-o\fP \fIoption\fP\fB][\fP\fB+abCefhimnuvx\fP\fB][\fP\fB+o\fP
\fIoption\fP\fB]\fP\fIcommand_string
.br
\fP \fB\ \ \ \ \ \ \fP \fI\fP\fB[\fP\fIcommand_name\fP
\fB[\fP\fIargument\fP\fB...\fP\fB]]\fP\fB
.br
.sp
sh -s\fP\fB[\fP\fB-abCefhimnuvx\fP\fB][\fP\fB-o\fP \fIoption\fP\fB][\fP\fB+abCefhimnuvx\fP\fB][\fP\fB+o\fP
\fIoption\fP\fB][\fP\fIargument\fP\fB]\fP\fB
.br
\fP
.SH DESCRIPTION
.LP
The \fIsh\fP utility is a command language interpreter that shall
execute commands read from a command line string, the
standard input, or a specified file. The application shall ensure
that the commands to be executed are expressed in the language
described in \fIShell Command Language\fP .
.LP
Pathname expansion shall not fail due to the size of a file.
.LP
Shell input and output redirections have an implementation-defined
offset maximum that is established in the open file
description.
.SH OPTIONS
.LP
The \fIsh\fP utility shall conform to the Base Definitions volume
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines,
with an extension for support of a leading
plus sign ( \fB'+'\fP ) as noted below.
.LP
The \fB-a\fP, \fB-b\fP, \fB-C\fP, \fB-e\fP, \fB-f\fP, \fB-m\fP, \fB-n\fP,
\fB-o\fP \fIoption\fP, \fB-u\fP, \fB-v\fP,
and \fB-x\fP options are described as part of the \fIset\fP utility
in \fISpecial Built-In Utilities\fP . The option letters derived from
the \fIset\fP special built-in shall also be accepted with a leading
plus sign ( \fB'+'\fP )
instead of a leading hyphen (meaning the reverse case of the option
as described in this volume of
IEEE\ Std\ 1003.1-2001).
.LP
The following additional options shall be supported:
.TP 7
\fB-c\fP
Read commands from the \fIcommand_string\fP operand. Set the value
of special parameter 0 (see \fISpecial Parameters\fP ) from the value
of the \fIcommand_name\fP operand and the positional
parameters ($1, $2, and so on) in sequence from the remaining \fIargument\fP
operands. No commands shall be read from the standard
input.
.TP 7
\fB-i\fP
Specify that the shell is \fIinteractive\fP; see below. An implementation
may treat specifying the \fB-i\fP option as an
error if the real user ID of the calling process does not equal the
effective user ID or if the real group ID does not equal the
effective group ID.
.TP 7
\fB-s\fP
Read commands from the standard input.
.sp
.LP
If there are no operands and the \fB-c\fP option is not specified,
the \fB-s\fP option shall be assumed.
.LP
If the \fB-i\fP option is present, or if there are no operands and
the shell's standard input and standard error are attached
to a terminal, the shell is considered to be \fIinteractive\fP.
.SH OPERANDS
.LP
The following operands shall be supported:
.TP 7
\fB-\fP
A single hyphen shall be treated as the first operand and then ignored.
If both \fB'-'\fP and \fB"--"\fP are given as
arguments, or if other operands precede the single hyphen, the results
are undefined.
.TP 7
\fIargument\fP
The positional parameters ($1, $2, and so on) shall be set to \fIarguments\fP,
if any.
.TP 7
\fIcommand_file\fP
The pathname of a file containing commands. If the pathname contains
one or more slash characters, the implementation attempts
to read that file; the file need not be executable. If the pathname
does not contain a slash character:
.RS
.IP " *" 3
The implementation shall attempt to read that file from the current
working directory; the file need not be executable.
.LP
.IP " *" 3
If the file is not in the current working directory, the implementation
may perform a search for an executable file using the
value of \fIPATH ,\fP as described in \fICommand Search and Execution\fP
\&.
.LP
.RE
.LP
Special parameter 0 (see \fISpecial Parameters\fP ) shall be set to
the value of
\fIcommand_file\fP. If \fIsh\fP is called using a synopsis form that
omits \fIcommand_file\fP, special parameter 0 shall be set
to the value of the first argument passed to \fIsh\fP from its parent
(for example, \fIargv\fP[0] for a C program), which is
normally a pathname used to execute the \fIsh\fP utility.
.TP 7
\fIcommand_name\fP
.sp
A string assigned to special parameter 0 when executing the commands
in \fIcommand_string\fP. If \fIcommand_name\fP is not
specified, special parameter 0 shall be set to the value of the first
argument passed to \fIsh\fP from its parent (for example,
\fIargv\fP[0] for a C program), which is normally a pathname used
to execute the \fIsh\fP utility.
.TP 7
\fIcommand_string\fP
.sp
A string that shall be interpreted by the shell as one or more commands,
as if the string were the argument to the \fIsystem\fP() function
defined in the System Interfaces volume of IEEE\ Std\ 1003.1-2001.
If the \fIcommand_string\fP operand is an empty string, \fIsh\fP shall
exit with a zero exit status.
.sp
.SH STDIN
.LP
The standard input shall be used only if one of the following is true:
.IP " *" 3
The \fB-s\fP option is specified.
.LP
.IP " *" 3
The \fB-c\fP option is not specified and no operands are specified.
.LP
.IP " *" 3
The script executes one or more commands that require input from standard
input (such as a \fIread\fP command that does not redirect its input).
.LP
.LP
See the INPUT FILES section.
.LP
When the shell is using standard input and it invokes a command that
also uses standard input, the shell shall ensure that the
standard input file pointer points directly after the command it has
read when the command begins execution. It shall not read
ahead in such a manner that any characters intended to be read by
the invoked command are consumed by the shell (whether
interpreted by the shell or not) or that characters that are not read
by the invoked command are not seen by the shell. When the
command expecting to read standard input is started asynchronously
by an interactive shell, it is unspecified whether characters
are read by the command or interpreted by the shell.
.LP
If the standard input to \fIsh\fP is a FIFO or terminal device and
is set to non-blocking reads, then \fIsh\fP shall enable
blocking reads on standard input. This shall remain in effect when
the command completes.
.SH INPUT FILES
.LP
The input file shall be a text file, except that line lengths shall
be unlimited. If the input file is empty or consists solely
of blank lines or comments, or both, \fIsh\fP shall exit with a zero
exit status.
.SH ENVIRONMENT VARIABLES
.LP
The following environment variables shall affect the execution of
\fIsh\fP:
.TP 7
\fIENV\fP
This variable, when and only when an interactive shell is invoked,
shall be subjected to parameter expansion (see \fIParameter Expansion\fP
) 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 \fIENV\fP is not an absolute pathname, the results are unspecified.
\fIENV\fP shall be ignored if the real and effective user
IDs or real and effective group IDs of the process are different.
.TP 7
\fIFCEDIT\fP
This variable, when expanded by the shell, shall determine the default
value for the \fB-e\fP \fIeditor\fP option's
\fIeditor\fP option-argument. If \fIFCEDIT\fP is null or unset, \fIed\fP
shall be used as the
editor. This volume of IEEE\ Std\ 1003.1-2001 specifies the effects
of this variable only for systems supporting the User
Portability Utilities option.
.TP 7
\fIHISTFILE\fP
Determine a pathname naming a command history file. If the \fIHISTFILE\fP
variable is not set, the shell may attempt to access
or create a file \fB.sh_history\fP in the directory referred to by
the \fIHOME\fP environment variable. If the shell cannot
obtain both read and write access to, or create, the history file,
it shall use an unspecified mechanism that allows the history to
operate properly. (References to history "file" in this section shall
be understood to mean this unspecified mechanism in such
cases.) An implementation may choose to access this variable only
when initializing the history file; this initialization shall
occur when \fIfc\fP or \fIsh\fP first attempt to retrieve entries
from, or add entries to, the
file, as the result of commands issued by the user, the file named
by the \fIENV\fP variable, or implementation-defined system
start-up files. Implementations may choose to disable the history
list mechanism for users with appropriate privileges who do not
set \fIHISTFILE ;\fP the specific circumstances under which this occurs
are implementation-defined. If more than one instance of
the shell is using the same history file, it is unspecified how updates
to the history file from those shells interact. As entries
are deleted from the history file, they shall be deleted oldest first.
It is unspecified when history file entries are physically
removed from the history file. This volume of IEEE\ Std\ 1003.1-2001
specifies the effects of this variable only for
systems supporting the User Portability Utilities option.
.TP 7
\fIHISTSIZE\fP
Determine a decimal number representing the limit to the number of
previous commands that are accessible. If this variable is
unset, an unspecified default greater than or equal to 128 shall be
used. The maximum number of commands in the history list is
unspecified, but shall be at least 128. An implementation may choose
to access this variable only when initializing the history
file, as described under \fIHISTFILE .\fP Therefore, it is unspecified
whether changes made to \fIHISTSIZE\fP after the history
file has been initialized are effective.
.TP 7
\fIHOME\fP
Determine the pathname of the user's home directory. The contents
of \fIHOME\fP are used in tilde expansion as described in \fITilde
Expansion\fP . This volume of IEEE\ Std\ 1003.1-2001 specifies the
effects of this variable only for systems supporting the User Portability
Utilities option.
.TP 7
\fIIFS\fP
(Input Field Separators.) A string treated as a list of characters
that shall be used for field splitting and to split lines
into words with the \fIread\fP command. See \fIField
Splitting\fP . If \fIIFS\fP is not set, the shell shall behave as
if the value of \fIIFS\fP were <space>, <tab>,
and <newline>. Implementations may ignore the value of \fIIFS\fP in
the environment at the time \fIsh\fP is invoked,
treating \fIIFS\fP as if it were not set.
.TP 7
\fILANG\fP
Provide a default value for the internationalization variables that
are unset or null. (See the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
for
the precedence of internationalization variables used to determine
the values of locale categories.)
.TP 7
\fILC_ALL\fP
If set to a non-empty string value, override the values of all the
other internationalization variables.
.TP 7
\fILC_COLLATE\fP
.sp
Determine the behavior of range expressions, equivalence classes,
and multi-character collating elements within pattern
matching.
.TP 7
\fILC_CTYPE\fP
Determine the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments and input files), which
characters are defined as letters (character class
\fBalpha\fP), and the behavior of character classes within pattern
matching.
.TP 7
\fILC_MESSAGES\fP
Determine the locale that should be used to affect the format and
contents of diagnostic messages written to standard
error.
.TP 7
\fIMAIL\fP
Determine a pathname of the user's mailbox file for purposes of incoming
mail notification. If this variable is set, the shell
shall inform the user if the file named by the variable is created
or if its modification time has changed. Informing the user
shall be accomplished by writing a string of unspecified format to
standard error prior to the writing of the next primary prompt
string. Such check shall be performed only after the completion of
the interval defined by the \fIMAILCHECK\fP variable after the
last such check. The user shall be informed only if \fIMAIL\fP is
set and \fIMAILPATH\fP is not set. This volume of
IEEE\ Std\ 1003.1-2001 specifies the effects of this variable only
for systems supporting the User Portability Utilities
option.
.TP 7
\fIMAILCHECK\fP
.sp
Establish a decimal integer value that specifies how often (in seconds)
the shell shall check for the arrival of mail in the files
specified by the \fIMAILPATH\fP or \fIMAIL\fP variables. The default
value shall be 600 seconds. If set to zero, the shell shall
check before issuing each primary prompt. This volume of IEEE\ Std\ 1003.1-2001
specifies the effects of this variable only
for systems supporting the User Portability Utilities option.
.TP 7
\fIMAILPATH\fP
Provide a list of pathnames and optional messages separated by colons.
If this variable is set, the shell shall inform the user
if any of the files named by the variable are created or if any of
their modification times change. (See the preceding entry for
\fIMAIL\fP for descriptions of mail arrival and user informing.) Each
pathname can be followed by \fB'%'\fP and a string that
shall be subjected to parameter expansion and written to standard
error when the modification time changes. If a \fB'%'\fP
character in the pathname is preceded by a backslash, it shall be
treated as a literal \fB'%'\fP in the pathname. The default
message is unspecified.
.LP
The \fIMAILPATH\fP environment variable takes precedence over the
\fIMAIL\fP variable. This volume of
IEEE\ Std\ 1003.1-2001 specifies the effects of this variable only
for systems supporting the User Portability Utilities
option.
.TP 7
\fINLSPATH\fP
Determine the location of message catalogs for the processing of \fILC_MESSAGES
\&.\fP
.TP 7
\fIPATH\fP
Establish a string formatted as described in the Base Definitions
volume of IEEE\ Std\ 1003.1-2001, Chapter 8, Environment Variables,
used to effect command interpretation; see \fICommand Search and Execution\fP
\&.
.TP 7
\fIPWD\fP
This variable shall represent an absolute pathname of the current
working directory. Assignments to this variable may be
ignored unless the value is an absolute pathname of the current working
directory and there are no filename components of dot or
dot-dot.
.sp
.SH ASYNCHRONOUS EVENTS
.LP
Default.
.SH STDOUT
.LP
See the STDERR section.
.SH STDERR
.LP
Except as otherwise stated (by the descriptions of any invoked utilities
or in interactive mode), standard error shall be used
only for diagnostic messages.
.SH OUTPUT FILES
.LP
None.
.SH EXTENDED DESCRIPTION
.LP
See \fIShell Command Language\fP . The following additional capabilities
are supported on
systems supporting the User Portability Utilities option.
.SS Command History List
.LP
When the \fIsh\fP utility is being used interactively, it shall maintain
a list of commands previously entered from the
terminal in the file named by the \fIHISTFILE\fP environment variable.
The type, size, and internal format of this file are
unspecified. Multiple \fIsh\fP processes can share access to the file
for a user, if file access permissions allow this; see the
description of the \fIHISTFILE\fP environment variable.
.SS Command Line Editing
.LP
When \fIsh\fP is being used interactively from a terminal, the current
command and the command history (see \fIfc\fP ) can be edited using
\fIvi\fP-mode command line editing. This mode
uses commands, described below, similar to a subset of those described
in the \fIvi\fP utility.
Implementations may offer other command line editing modes corresponding
to other editing utilities.
.LP
The command \fIset\fP \fB-o\fP \fIvi\fP
shall enable \fIvi\fP-mode editing and place \fIsh\fP into \fIvi\fP
insert mode (see Command Line Editing (vi-mode) ). This
command also shall disable any other editing mode that the implementation
may provide. The command \fIset\fP \fB+o\fP \fIvi\fP disables \fIvi\fP-mode
editing.
.LP
Certain block-mode terminals may be unable to support shell command
line editing. If a terminal is unable to provide either edit
mode, it need not be possible to \fIset\fP \fB-o\fP \fIvi\fP when
using the shell on this terminal.
.LP
In the following sections, the characters \fIerase\fP, \fIinterrupt\fP,
\fIkill\fP, and \fIend-of-file\fP are those set by
the \fIstty\fP utility.
.SS Command Line Editing (vi-mode)
.LP
In \fIvi\fP editing mode, there shall be a distinguished line, the
edit line. All the
editing operations which modify a line affect the edit line. The edit
line is always the newest line in the command history
buffer.
.LP
With \fIvi\fP-mode enabled, \fIsh\fP can be switched between insert
mode and command
mode.
.LP
When in insert mode, an entered character shall be inserted into the
command line, except as noted in vi Line Editing Insert Mode . Upon
entering \fIsh\fP and after termination of the previous command,
\fIsh\fP shall be in insert mode.
.LP
Typing an escape character shall switch \fIsh\fP into command mode
(see vi Line Editing Command
Mode ). In command mode, an entered character shall either invoke
a defined operation, be used as part of a multi-character
operation, or be treated as an error. A character that is not recognized
as part of an editing command shall terminate any specific
editing command and shall alert the terminal. Typing the \fIinterrupt\fP
character in command mode shall cause \fIsh\fP to
terminate command line editing on the current command line, reissue
the prompt on the next line of the terminal, and reset the
command history (see \fIfc\fP ) so that the most recently executed
command is the previous command (that is,
the command that was being edited when it was interrupted is not reentered
into the history).
.LP
In the following sections, the phrase "move the cursor to the beginning
of the word" shall mean "move the cursor to the first
character of the current word" and the phrase "move the cursor to
the end of the word" shall mean "move the cursor to the last
character of the current word". The phrase "beginning of the command
line" indicates the point between the end of the prompt
string issued by the shell (or the beginning of the terminal line,
if there is no prompt string) and the first character of the
command text.
.SS vi Line Editing Insert Mode
.LP
While in insert mode, any character typed shall be inserted in the
current command line, unless it is from the following
set.
.TP 7
<newline>
Execute the current command line. If the current command line is not
empty, this line shall be entered into the command history
(see \fIfc\fP ).
.TP 7
\fIerase\fP
Delete the character previous to the current cursor position and move
the current cursor position back one character. In insert
mode, characters shall be erased from both the screen and the buffer
when backspacing.
.TP 7
\fIinterrupt\fP
Terminate command line editing with the same effects as described
for interrupting command mode; see Command Line Editing (vi-mode)
\&.
.TP 7
\fIkill\fP
Clear all the characters from the input line.
.TP 7
<control>-V
Insert the next character input, even if the character is otherwise
a special insert mode character.
.TP 7
<control>-W
Delete the characters from the one preceding the cursor to the preceding
word boundary. The word boundary in this case is the
closer to the cursor of either the beginning of the line or a character
that is in neither the \fBblank\fP nor \fBpunct\fP
character classification of the current locale.
.TP 7
\fIend-of-file\fP
Interpreted as the end of input in \fIsh\fP. This interpretation shall
occur only at the beginning of an input line. If
\fIend-of-file\fP is entered other than at the beginning of the line,
the results are unspecified.
.TP 7
<ESC>
Place \fIsh\fP into command mode.
.sp
.SS vi Line Editing Command Mode
.LP
In command mode for the command line editing feature, decimal digits
not beginning with 0 that precede a command letter shall be
remembered. Some commands use these decimal digits as a count number
that affects the operation.
.LP
The term \fImotion command\fP represents one of the commands:
.sp
.RS
.nf
\fB<space> 0 b F l W ^ $ ; E f T w | , B e h t
\fP
.fi
.RE
.LP
If the current line is not the edit line, any command that modifies
the current line shall cause the content of the current line
to replace the content of the edit line, and the current line shall
become the edit line. This replacement cannot be undone (see
the \fBu\fP and \fBU\fP commands below). The modification requested
shall then be performed to the edit line. When the current
line is the edit line, the modification shall be done directly to
the edit line.
.LP
Any command that is preceded by \fIcount\fP shall take a count (the
numeric value of any preceding decimal digits). Unless
otherwise noted, this count shall cause the specified operation to
repeat by the number of times specified by the count. Also
unless otherwise noted, a \fIcount\fP that is out of range is considered
an error condition and shall alert the terminal, but
neither the cursor position, nor the command line, shall change.
.LP
The terms \fIword\fP and \fIbigword\fP are used as defined in the
\fIvi\fP description.
The term \fIsave buffer\fP corresponds to the term \fIunnamed buffer\fP
in \fIvi\fP.
.LP
The following commands shall be recognized in command mode:
.TP 7
<newline>
Execute the current command line. If the current command line is not
empty, this line shall be entered into the command history
(see \fIfc\fP ).
.TP 7
<control>-L
Redraw the current command line. Position the cursor at the same location
on the redrawn line.
.TP 7
\fB#\fP
Insert the character \fB'#'\fP at the beginning of the current command
line and treat the resulting edit line as a comment.
This line shall be entered into the command history; see \fIfc\fP
\&.
.TP 7
\fB=\fP
Display the possible shell word expansions (see \fIWord Expansions\fP
) of the bigword
at the current command line position.
.TP 7
\fBNote:\fP
.RS
This does not modify the content of the current line, and therefore
does not cause the current line to become the edit
line.
.RE
.sp
.LP
These expansions shall be displayed on subsequent terminal lines.
If the bigword contains none of the characters \fB'?'\fP ,
\fB'*'\fP , or \fB'['\fP , an asterisk ( \fB'*'\fP ) shall be implicitly
assumed at the end. If any directories are
matched, these expansions shall have a \fB'/'\fP character appended.
After the expansion, the line shall be redrawn, the cursor
repositioned at the current cursor position, and \fIsh\fP shall be
placed in command mode.
.TP 7
\fB\\\fP
Perform pathname expansion (see \fIPathname Expansion\fP ) on the
current bigword,
up to the largest set of characters that can be matched uniquely.
If the bigword contains none of the characters \fB'?'\fP ,
\fB'*'\fP , or \fB'['\fP , an asterisk ( \fB'*'\fP ) shall be implicitly
assumed at the end. This maximal expansion then
shall replace the original bigword in the command line, and the cursor
shall be placed after this expansion. If the resulting
bigword completely and uniquely matches a directory, a \fB'/'\fP character
shall be inserted directly after the bigword. If some
other file is completely matched, a single <space> shall be inserted
after the bigword. After this operation, \fIsh\fP shall
be placed in insert mode.
.TP 7
\fB*\fP
Perform pathname expansion on the current bigword and insert all expansions
into the command to replace the current bigword,
with each expansion separated by a single <space>. If at the end of
the line, the current cursor position shall be moved to
the first column position following the expansions and \fIsh\fP shall
be placed in insert mode. Otherwise, the current cursor
position shall be the last column position of the first character
after the expansions and \fIsh\fP shall be placed in insert
mode. If the current bigword contains none of the characters \fB'?'\fP
, \fB'*'\fP , or \fB'['\fP , before the operation,
an asterisk shall be implicitly assumed at the end.
.TP 7
\fB@\fP\fIletter\fP
Insert the value of the alias named \fI_letter\fP. The symbol \fIletter\fP
represents a single alphabetic character from the
portable character set; implementations may support additional characters
as an extension. If the alias \fI_letter\fP contains
other editing commands, these commands shall be performed as part
of the insertion. If no alias \fI_letter\fP is enabled, this
command shall have no effect.
.TP 7
\fB[\fP\fIcount\fP\fB]~\fP
Convert, if the current character is a lowercase letter, to the equivalent
uppercase letter and \fIvice versa\fP, as
prescribed by the current locale. The current cursor position then
shall be advanced by one character. If the cursor was positioned
on the last character of the line, the case conversion shall occur,
but the cursor shall not advance. If the \fB'~'\fP
command is preceded by a \fIcount\fP, that number of characters shall
be converted, and the cursor shall be advanced to the
character position after the last character converted. If the \fIcount\fP
is larger than the number of characters after the
cursor, this shall not be considered an error; the cursor shall advance
to the last character on the line.
.TP 7
\fB[\fP\fIcount\fP\fB].\fP
Repeat the most recent non-motion command, even if it was executed
on an earlier command line. If the previous command was
preceded by a \fIcount\fP, and no count is given on the \fB'.'\fP
command, the count from the previous command shall be
included as part of the repeated command. If the \fB'.'\fP command
is preceded by a \fIcount\fP, this shall override any
\fIcount\fP argument to the previous command. The \fIcount\fP specified
in the \fB'.'\fP command shall become the count for
subsequent \fB'.'\fP commands issued without a count.
.TP 7
\fB[\fP\fInumber\fP\fB]v\fP
Invoke the \fIvi\fP editor to edit the current command line in a temporary
file. When the
editor exits, the commands in the temporary file shall be executed
and placed in the command history. If a \fInumber\fP is
included, it specifies the command number in the command history to
be edited, rather than the current command line.
.TP 7
\fB[\fP\fIcount\fP\fB]l\fP\ \ \ (ell)
.TP 7
\fB[\fP\fIcount\fP\fB]\fP<space>
.sp
Move the current cursor position to the next character position. If
the cursor was positioned on the last character of the line,
the terminal shall be alerted and the cursor shall not be advanced.
If the \fIcount\fP is larger than the number of characters
after the cursor, this shall not be considered an error; the cursor
shall advance to the last character on the line.
.TP 7
\fB[\fP\fIcount\fP\fB]h\fP
Move the current cursor position to the \fIcount\fPth (default 1)
previous character position. If the cursor was positioned on
the first character of the line, the terminal shall be alerted and
the cursor shall not be moved. If the count is larger than the
number of characters before the cursor, this shall not be considered
an error; the cursor shall move to the first character on the
line.
.TP 7
\fB[\fP\fIcount\fP\fB]w\fP
Move to the start of the next word. If the cursor was positioned on
the last character of the line, the terminal shall be
alerted and the cursor shall not be advanced. If the \fIcount\fP is
larger than the number of words after the cursor, this shall
not be considered an error; the cursor shall advance to the last character
on the line.
.TP 7
\fB[\fP\fIcount\fP\fB]W\fP
Move to the start of the next bigword. If the cursor was positioned
on the last character of the line, the terminal shall be
alerted and the cursor shall not be advanced. If the \fIcount\fP is
larger than the number of bigwords after the cursor, this
shall not be considered an error; the cursor shall advance to the
last character on the line.
.TP 7
\fB[\fP\fIcount\fP\fB]e\fP
Move to the end of the current word. If at the end of a word, move
to the end of the next word. If the cursor was positioned on
the last character of the line, the terminal shall be alerted and
the cursor shall not be advanced. If the \fIcount\fP is larger
than the number of words after the cursor, this shall not be considered
an error; the cursor shall advance to the last character on
the line.
.TP 7
\fB[\fP\fIcount\fP\fB]E\fP
Move to the end of the current bigword. If at the end of a bigword,
move to the end of the next bigword. If the cursor was
positioned on the last character of the line, the terminal shall be
alerted and the cursor shall not be advanced. If the
\fIcount\fP is larger than the number of bigwords after the cursor,
this shall not be considered an error; the cursor shall
advance to the last character on the line.
.TP 7
\fB[\fP\fIcount\fP\fB]b\fP
Move to the beginning of the current word. If at the beginning of
a word, move to the beginning of the previous word. If the
cursor was positioned on the first character of the line, the terminal
shall be alerted and the cursor shall not be moved. If the
\fIcount\fP is larger than the number of words preceding the cursor,
this shall not be considered an error; the cursor shall
return to the first character on the line.
.TP 7
\fB[\fP\fIcount\fP\fB]B\fP
Move to the beginning of the current bigword. If at the beginning
of a bigword, move to the beginning of the previous bigword.
If the cursor was positioned on the first character of the line, the
terminal shall be alerted and the cursor shall not be moved.
If the \fIcount\fP is larger than the number of bigwords preceding
the cursor, this shall not be considered an error; the cursor
shall return to the first character on the line.
.TP 7
\fB^\fP
Move the current cursor position to the first character on the input
line that is not a <blank>.
.TP 7
\fB$\fP
Move to the last character position on the current command line.
.TP 7
\fB0\fP
(Zero.) Move to the first character position on the current command
line.
.TP 7
\fB[\fP\fIcount\fP\fB]|\fP
Move to the \fIcount\fPth character position on the current command
line. If no number is specified, move to the first
position. The first character position shall be numbered 1. If the
count is larger than the number of characters on the line, this
shall not be considered an error; the cursor shall be placed on the
last character on the line.
.TP 7
\fB[\fP\fIcount\fP\fB]f\fP\fIc\fP
Move to the first occurrence of the character \fB'c'\fP that occurs
after the current cursor position. If the cursor was
positioned on the last character of the line, the terminal shall be
alerted and the cursor shall not be advanced. If the character
\fB'c'\fP does not occur in the line after the current cursor position,
the terminal shall be alerted and the cursor shall not
be moved.
.TP 7
\fB[\fP\fIcount\fP\fB]F\fP\fIc\fP
Move to the first occurrence of the character \fB'c'\fP that occurs
before the current cursor position. If the cursor was
positioned on the first character of the line, the terminal shall
be alerted and the cursor shall not be moved. If the character
\fB'c'\fP does not occur in the line before the current cursor position,
the terminal shall be alerted and the cursor shall not
be moved.
.TP 7
\fB[\fP\fIcount\fP\fB]t\fP\fIc\fP
Move to the character before the first occurrence of the character
\fB'c'\fP that occurs after the current cursor position.
If the cursor was positioned on the last character of the line, the
terminal shall be alerted and the cursor shall not be advanced.
If the character \fB'c'\fP does not occur in the line after the current
cursor position, the terminal shall be alerted and the
cursor shall not be moved.
.TP 7
\fB[\fP\fIcount\fP\fB]T\fP\fIc\fP
Move to the character after the first occurrence of the character
\fB'c'\fP that occurs before the current cursor position.
If the cursor was positioned on the first character of the line, the
terminal shall be alerted and the cursor shall not be moved.
If the character \fB'c'\fP does not occur in the line before the current
cursor position, the terminal shall be alerted and the
cursor shall not be moved.
.TP 7
\fB[\fP\fIcount\fP\fB];\fP
Repeat the most recent \fBf\fP, \fBF\fP, \fBt\fP, or \fBT\fP command.
Any number argument on that previous command shall be
ignored. Errors are those described for the repeated command.
.TP 7
\fB[\fP\fIcount\fP\fB],\fP
Repeat the most recent \fBf\fP, \fBF\fP, \fBt\fP, or \fBT\fP command.
Any number argument on that previous command shall be
ignored. However, reverse the direction of that command.
.TP 7
\fBa\fP
Enter insert mode after the current cursor position. Characters that
are entered shall be inserted before the next
character.
.TP 7
\fBA\fP
Enter insert mode after the end of the current command line.
.TP 7
\fBi\fP
Enter insert mode at the current cursor position. Characters that
are entered shall be inserted before the current
character.
.TP 7
\fBI\fP
Enter insert mode at the beginning of the current command line.
.TP 7
\fBR\fP
Enter insert mode, replacing characters from the command line beginning
at the current cursor position.
.TP 7
\fB[\fP\fIcount\fP\fB]c\fP\fImotion\fP
.sp
Delete the characters between the current cursor position and the
cursor position that would result from the specified motion
command. Then enter insert mode before the first character following
any deleted characters. If \fIcount\fP is specified, it shall
be applied to the motion command. A \fIcount\fP shall be ignored for
the following motion commands:
.sp
.RS
.nf
\fB0 ^ $ c
\fP
.fi
.RE
.LP
If the motion command is the character \fB'c'\fP , the current command
line shall be cleared and insert mode shall be
entered. If the motion command would move the current cursor position
toward the beginning of the command line, the character under
the current cursor position shall not be deleted. If the motion command
would move the current cursor position toward the end of
the command line, the character under the current cursor position
shall be deleted. If the \fIcount\fP is larger than the number
of characters between the current cursor position and the end of the
command line toward which the motion command would move the
cursor, this shall not be considered an error; all of the remaining
characters in the aforementioned range shall be deleted and
insert mode shall be entered. If the motion command is invalid, the
terminal shall be alerted, the cursor shall not be moved, and
no text shall be deleted.
.TP 7
\fBC\fP
Delete from the current character to the end of the line and enter
insert mode at the new end-of-line.
.TP 7
\fBS\fP
Clear the entire edit line and enter insert mode.
.TP 7
\fB[\fP\fIcount\fP\fB]r\fP\fIc\fP
Replace the current character with the character \fB'c'\fP . With
a number \fIcount\fP, replace the current and the
following \fIcount\fP-1 characters. After this command, the current
cursor position shall be on the last character that was
changed. If the \fIcount\fP is larger than the number of characters
after the cursor, this shall not be considered an error; all
of the remaining characters shall be changed.
.TP 7
\fB[\fP\fIcount\fP\fB]_\fP
Append a <space> after the current character position and then append
the last bigword in the previous input line after
the <space>. Then enter insert mode after the last character just
appended. With a number \fIcount\fP, append the
\fIcount\fPth bigword in the previous line.
.TP 7
\fB[\fP\fIcount\fP\fB]x\fP
Delete the character at the current cursor position and place the
deleted characters in the save buffer. If the cursor was
positioned on the last character of the line, the character shall
be deleted and the cursor position shall be moved to the previous
character (the new last character). If the \fIcount\fP is larger than
the number of characters after the cursor, this shall not be
considered an error; all the characters from the cursor to the end
of the line shall be deleted.
.TP 7
\fB[\fP\fIcount\fP\fB]X\fP
Delete the character before the current cursor position and place
the deleted characters in the save buffer. The character
under the current cursor position shall not change. If the cursor
was positioned on the first character of the line, the terminal
shall be alerted, and the \fBX\fP command shall have no effect. If
the line contained a single character, the \fBX\fP command
shall have no effect. If the line contained no characters, the terminal
shall be alerted and the cursor shall not be moved. If the
\fIcount\fP is larger than the number of characters before the cursor,
this shall not be considered an error; all the characters
from before the cursor to the beginning of the line shall be deleted.
.TP 7
\fB[\fP\fIcount\fP\fB]d\fP\fImotion\fP
.sp
Delete the characters between the current cursor position and the
character position that would result from the motion command. A
number \fIcount\fP repeats the motion command \fIcount\fP times. If
the motion command would move toward the beginning of the
command line, the character under the current cursor position shall
not be deleted. If the motion command is \fBd\fP, the entire
current command line shall be cleared. If the \fIcount\fP is larger
than the number of characters between the current cursor
position and the end of the command line toward which the motion command
would move the cursor, this shall not be considered an
error; all of the remaining characters in the aforementioned range
shall be deleted. The deleted characters shall be placed in the
save buffer.
.TP 7
\fBD\fP
Delete all characters from the current cursor position to the end
of the line. The deleted characters shall be placed in the
save buffer.
.TP 7
\fB[\fP\fIcount\fP\fB]y\fP\fImotion\fP
.sp
Yank (that is, copy) the characters from the current cursor position
to the position resulting from the motion command into the
save buffer. A number \fIcount\fP shall be applied to the motion command.
If the motion command would move toward the beginning of
the command line, the character under the current cursor position
shall not be included in the set of yanked characters. If the
motion command is \fBy\fP, the entire current command line shall be
yanked into the save buffer. The current cursor position shall
be unchanged. If the \fIcount\fP is larger than the number of characters
between the current cursor position and the end of the
command line toward which the motion command would move the cursor,
this shall not be considered an error; all of the remaining
characters in the aforementioned range shall be yanked.
.TP 7
\fBY\fP
Yank the characters from the current cursor position to the end of
the line into the save buffer. The current character
position shall be unchanged.
.TP 7
\fB[\fP\fIcount\fP\fB]p\fP
Put a copy of the current contents of the save buffer after the current
cursor position. The current cursor position shall be
advanced to the last character put from the save buffer. A \fIcount\fP
shall indicate how many copies of the save buffer shall be
put.
.TP 7
\fB[\fP\fIcount\fP\fB]P\fP
Put a copy of the current contents of the save buffer before the current
cursor position. The current cursor position shall be
moved to the last character put from the save buffer. A \fIcount\fP
shall indicate how many copies of the save buffer shall be
put.
.TP 7
\fBu\fP
Undo the last command that changed the edit line. This operation shall
not undo the copy of any command line to the edit
line.
.TP 7
\fBU\fP
Undo all changes made to the edit line. This operation shall not undo
the copy of any command line to the edit line.
.TP 7
\fB[\fP\fIcount\fP\fB]k\fP
.TP 7
\fB[\fP\fIcount\fP\fB]-\fP
Set the current command line to be the \fIcount\fPth previous command
line in the shell command history. If \fIcount\fP is
not specified, it shall default to 1. The cursor shall be positioned
on the first character of the new command. If a \fBk\fP or
\fB-\fP command would retreat past the maximum number of commands
in effect for this shell (affected by the \fIHISTSIZE\fP
environment variable), the terminal shall be alerted, and the command
shall have no effect.
.TP 7
\fB[\fP\fIcount\fP\fB]j\fP
.TP 7
\fB[\fP\fIcount\fP\fB]+\fP
Set the current command line to be the \fIcount\fPth next command
line in the shell command history. If \fIcount\fP is not
specified, it shall default to 1. The cursor shall be positioned on
the first character of the new command. If a \fBj\fP or
\fB+\fP command advances past the edit line, the current command line
shall be restored to the edit line and the terminal shall be
alerted.
.TP 7
\fB[\fP\fInumber\fP\fB]G\fP
Set the current command line to be the oldest command line stored
in the shell command history. With a number \fInumber\fP,
set the current command line to be the command line \fInumber\fP in
the history. If command line \fInumber\fP does not exist, the
terminal shall be alerted and the command line shall not be changed.
.TP 7
\fB/\fP\fIpattern\fP<newline>
.sp
Move backwards through the command history, searching for the specified
pattern, beginning with the previous command line. Patterns
use the pattern matching notation described in \fIPattern Matching
Notation\fP , except
that the \fB'^'\fP character shall have special meaning when it appears
as the first character of \fIpattern\fP. In this case,
the \fB'^'\fP is discarded and the characters after the \fB'^'\fP
shall be matched only at the beginning of a line. Commands
in the command history shall be treated as strings, not as filenames.
If the pattern is not found, the current command line shall
be unchanged and the terminal is alerted. If it is found in a previous
line, the current command line shall be set to that line and
the cursor shall be set to the first character of the new command
line.
.LP
If \fIpattern\fP is empty, the last non-empty pattern provided to
\fB/\fP or \fB?\fP shall be used. If there is no previous
non-empty pattern, the terminal shall be alerted and the current command
line shall remain unchanged.
.TP 7
\fB?\fP\fIpattern\fP<newline>
.sp
Move forwards through the command history, searching for the specified
pattern, beginning with the next command line. Patterns use
the pattern matching notation described in \fIPattern Matching Notation\fP
, except that
the \fB'^'\fP character shall have special meaning when it appears
as the first character of \fIpattern\fP. In this case, the
\fB'^'\fP is discarded and the characters after the \fB'^'\fP shall
be matched only at the beginning of a line. Commands in
the command history shall be treated as strings, not as filenames.
If the pattern is not found, the current command line shall be
unchanged and the terminal alerted. If it is found in a following
line, the current command line shall be set to that line and the
cursor shall be set to the fist character of the new command line.
.LP
If \fIpattern\fP is empty, the last non-empty pattern provided to
\fB/\fP or \fB?\fP shall be used. If there is no previous
non-empty pattern, the terminal shall be alerted and the current command
line shall remain unchanged.
.TP 7
\fBn\fP
Repeat the most recent \fB/\fP or \fB?\fP command. If there is no
previous \fB/\fP or \fB?\fP, the terminal shall be
alerted and the current command line shall remain unchanged.
.TP 7
\fBN\fP
Repeat the most recent \fB/\fP or \fB?\fP command, reversing the direction
of the search. If there is no previous \fB/\fP or
\fB?\fP, the terminal shall be alerted and the current command line
shall remain unchanged.
.sp
.SH EXIT STATUS
.LP
The following exit values shall be returned:
.TP 7
\ \ \ \ 0
The script to be executed consisted solely of zero or more blank lines
or comments, or both.
.TP 7
1-125
A non-interactive shell detected a syntax, redirection, or variable
assignment error.
.TP 7
\ \ 127
A specified \fIcommand_file\fP could not be found by a non-interactive
shell.
.sp
.LP
Otherwise, the shell shall return the exit status of the last command
it invoked or attempted to invoke (see also the \fIexit\fP utility
in \fISpecial Built-In
Utilities\fP ).
.SH CONSEQUENCES OF ERRORS
.LP
See \fIConsequences of Shell Errors\fP .
.LP
\fIThe following sections are informative.\fP
.SH APPLICATION USAGE
.LP
Standard input and standard error are the files that determine whether
a shell is interactive when \fB-i\fP is not specified.
For example:
.sp
.RS
.nf
\fBsh > file
\fP
.fi
.RE
.LP
and:
.sp
.RS
.nf
\fBsh 2> file
\fP
.fi
.RE
.LP
create interactive and non-interactive shells, respectively. Although
both accept terminal input, the results of error
conditions are different, as described in \fIConsequences of Shell
Errors\fP ; in the
second example a redirection error encountered by a special built-in
utility aborts the shell.
.LP
A conforming application must protect its first operand, if it starts
with a plus sign, by preceding it with the \fB"--"\fP
argument that denotes the end of the options.
.LP
Applications should note that the standard \fIPATH\fP to the shell
cannot be assumed to be either \fB/bin/sh\fP or
\fB/usr/bin/sh\fP, and should be determined by interrogation of the
\fIPATH\fP returned by \fIgetconf\fP \fIPATH ,\fP ensuring that the
returned pathname is an absolute pathname and not a
shell built-in.
.LP
For example, to determine the location of the standard \fIsh\fP utility:
.sp
.RS
.nf
\fBcommand -v sh
\fP
.fi
.RE
.LP
On some implementations this might return:
.sp
.RS
.nf
\fB/usr/xpg4/bin/sh
\fP
.fi
.RE
.LP
Furthermore, on systems that support executable scripts (the \fB"#!"\fP
construct), it is recommended that applications using
executable scripts install them using \fIgetconf\fP \fB-v\fP to determine
the shell
pathname and update the \fB"#!"\fP script appropriately as it is being
installed (for example, with \fIsed\fP). For example:
.sp
.RS
.nf
\fB#
# Installation time script to install correct POSIX shell pathname
#
# Get list of paths to check
#
Sifs=$IFS
IFS=:
set $(getconf PATH)
IFS=$Sifs
#
# Check each path for 'sh'
#
for i in $@
do
if [ -f ${i}/sh ];
then
Pshell=${i}/sh
fi
done
#
# This is the list of scripts to update. They should be of the
# form '${name}.source' and will be transformed to '${name}'.
# Each script should begin:
#
# !INSTALLSHELLPATH -p
#
scripts="a b c"
#
# Transform each script
#
for i in ${scripts}
do
sed -e "s|INSTALLSHELLPATH|${Pshell}|" < ${i}.source > ${i}
done
\fP
.fi
.RE
.SH EXAMPLES
.IP " 1." 4
Execute a shell command from a string:
.sp
.RS
.nf
\fBsh -c "cat myfile"
\fP
.fi
.RE
.LP
.IP " 2." 4
Execute a shell script from a file in the current directory:
.sp
.RS
.nf
\fBsh my_shell_cmds
\fP
.fi
.RE
.LP
.SH RATIONALE
.LP
The \fIsh\fP utility and the \fIset\fP special built-in utility share
a common
set of options.
.LP
The KornShell ignores the contents of \fIIFS\fP upon entry to the
script. A conforming application cannot rely on importing
\fIIFS .\fP One justification for this, beyond security considerations,
is to assist possible future shell compilers. Allowing
\fIIFS\fP to be imported from the environment prevents many optimizations
that might otherwise be performed via dataflow analysis
of the script itself.
.LP
The text in the STDIN section about non-blocking reads concerns an
instance of \fIsh\fP that has been invoked, probably by a
C-language program, with standard input that has been opened using
the O_NONBLOCK flag; see \fIopen\fP() in the System Interfaces volume
of IEEE\ Std\ 1003.1-2001. If the shell did not
reset this flag, it would immediately terminate because no input data
would be available yet and that would be considered the same
as end-of-file.
.LP
The options associated with a \fIrestricted shell\fP (command name
\fIrsh\fP and the \fB-r\fP option) were excluded because
the standard developers considered that the implied level of security
could not be achieved and they did not want to raise false
expectations.
.LP
On systems that support set-user-ID scripts, a historical trapdoor
has been to link a script to the name \fB-i\fP. When it is
called by a sequence such as:
.sp
.RS
.nf
\fBsh -
\fP
.fi
.RE
.LP
or by:
.sp
.RS
.nf
\fB#! usr/bin/sh -
\fP
.fi
.RE
.LP
the historical systems have assumed that no option letters follow.
Thus, this volume of IEEE\ Std\ 1003.1-2001 allows
the single hyphen to mark the end of the options, in addition to the
use of the regular \fB"--"\fP argument, because it was
considered that the older practice was so pervasive. An alternative
approach is taken by the KornShell, where real and effective
user/group IDs must match for an interactive shell; this behavior
is specifically allowed by this volume of
IEEE\ Std\ 1003.1-2001.
.TP 7
\fBNote:\fP
There are other problems with set-user-ID scripts that the two approaches
described here do not resolve.
.sp
.LP
The initialization process for the history file can be dependent on
the system start-up files, in that they may contain commands
that effectively preempt the user's settings of \fIHISTFILE\fP and
\fIHISTSIZE .\fP For example, function definition commands are
recorded in the history file, unless the \fIset\fP \fB-o\fP \fInolog\fP
option is
set. If the system administrator includes function definitions in
some system start-up file called before the \fIENV\fP file, the
history file is initialized before the user gets a chance to influence
its characteristics. In some historical shells, the history
file is initialized just after the \fIENV\fP file has been processed.
Therefore, it is implementation-defined whether changes made
to \fIHISTFILE\fP after the history file has been initialized are
effective.
.LP
The default messages for the various \fIMAIL -related\fP messages
are unspecified because they vary across implementations.
Typical messages are:
.sp
.RS
.nf
\fB"you have mail\\n"
\fP
.fi
.RE
.LP
or:
.sp
.RS
.nf
\fB"you have new mail\\n"
\fP
.fi
.RE
.LP
It is important that the descriptions of command line editing refer
to the same shell as that in IEEE\ Std\ 1003.1-2001
so that interactive users can also be application programmers without
having to deal with programmatic differences in their two
environments. It is also essential that the utility name \fIsh\fP
be specified because this explicit utility name is too firmly
rooted in historical practice of application programs for it to change.
.LP
Consideration was given to mandating a diagnostic message when attempting
to set \fIvi\fP-mode on terminals that do not support command line
editing. However, it is not historical
practice for the shell to be cognizant of all terminal types and thus
be able to detect inappropriate terminals in all cases.
Implementations are encouraged to supply diagnostics in this case
whenever possible, rather than leaving the user in a state where
editing commands work incorrectly.
.LP
In early proposals, the KornShell-derived \fIemacs\fP mode of command
line editing was included, even though the \fIemacs\fP
editor itself was not. The community of \fIemacs\fP proponents was
adamant that the full \fIemacs\fP editor not be standardized
because they were concerned that an attempt to standardize this very
powerful environment would encourage vendors to ship strictly
conforming versions lacking the extensibility required by the community.
The author of the original \fIemacs\fP program also
expressed his desire to omit the program. Furthermore, there were
a number of historical systems that did not include \fIemacs\fP,
or included it without supporting it, but there were very few that
did not include and support \fIvi\fP. The shell \fIemacs\fP command
line editing mode was finally omitted because it became
apparent that the KornShell version and the editor being distributed
with the GNU system had diverged in some respects. The author
of \fIemacs\fP requested that the POSIX \fIemacs\fP mode either be
deleted or have a significant number of unspecified
conditions. Although the KornShell author agreed to consider changes
to bring the shell into alignment, the standard developers
decided to defer specification at that time. At the time, it was assumed
that convergence on an acceptable definition would occur
for a subsequent draft, but that has not happened, and there appears
to be no impetus to do so. In any case, implementations are
free to offer additional command line editing modes based on the exact
models of editors their users are most comfortable with.
.LP
Early proposals had the following list entry in vi Line Editing Insert
Mode :
.TP 7
\fB\\\fP
If followed by the \fIerase\fP or \fIkill\fP character, that character
shall be inserted into the input line. Otherwise, the
backslash itself shall be inserted into the input line.
.sp
.LP
However, this is not actually a feature of \fIsh\fP command line editing
insert mode, but one of some historical terminal line
drivers. Some conforming implementations continue to do this when
the \fIstty\fP
\fBiexten\fP flag is set.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIShell Command Language\fP , \fIcd\fP , \fIecho\fP , \fIexit\fP()
, \fIfc\fP , \fIpwd\fP , \fIread\fP() , \fIset\fP , \fIstty\fP , \fItest\fP
, \fIumask\fP() , \fIvi\fP , the System Interfaces volume of IEEE\ Std\ 1003.1-2001,
\fIdup\fP(), \fIexec\fP, \fIexit\fP(), \fIfork\fP(), \fIopen\fP(),
\fIpipe\fP(), \fIsignal\fP(), \fIsystem\fP(), \fIulimit\fP(), \fIumask\fP(),
\fIwait\fP()
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
|