1 2 3 4SH(1) 1991 SH(1) 5 6 7NNAAMMEE 8 ash - a shell 9 10SSYYNNOOPPSSIISS 11 aasshh [ --eeffIIiijjnnssxxzz ] [ ++eeffIIiijjnnssxxzz ] [ --cc _c_o_m_m_a_n_d ] [ _a_r_g ] 12 ... 13 14CCOOPPYYRRIIGGHHTT 15 Copyright 1989 by Kenneth Almquist. 16 17DDEESSCCRRIIPPTTIIOONN 18 _A_s_h is a version of _s_h with features similar to those of 19 the System V shell. This manual page lists all the 20 features of _a_s_h but concentrates on the ones not in other 21 shells. 22 23 IInnvvooccaattiioonn 24 25 If the --cc options is given, then the shell executes the 26 specified shell command. The --ss flag cause the shell to 27 read commands from the standard input (after executing any 28 command specified with the --cc option. If neither the --ss 29 or --cc options are set, then the first _a_r_g is taken as the 30 name of a file to read commands from. If this is 31 impossible because there are no arguments following the 32 options, then _a_s_h will set the --ss flag and will read 33 commands from the standard input. 34 35 The shell sets the initial value of the positional 36 parameters from the _a_r_gs remaining after any _a_r_g used as 37 the name of a file of commands is deleted. 38 39 The flags (other than --cc) are set by preceding them with 40 ``-'' and cleared by preceding them with ``+''; see the 41 _s_e_t builtin command for a list of flags. If no value is 42 specified for the --ii flag, the --ss flag is set, and the 43 standard input and output of the shell are connected to 44 terminals, then the --ii flag will be set. If no value is 45 specified for the --jj flag, then the --jj flag will be set if 46 the --ii flag is set. 47 48 When the shell is invoked with the --cc option, it is good 49 practice to include the -_i flag if the command was entered 50 interactively by a user. For compatibility with the 51 System V shell, the -_i option should come after the --cc 52 option. 53 54 If the first character of argument zero to the shell is 55 ``-'', the shell is assumed to be a login shell, and the 56 files //eettcc//pprrooffiillee and ..pprrooffiillee are read if they exist. 57 If the environment variable SHINIT is set on entry to the 58 shell, the commands in SHINIT are normally parsed and 59 executed. SHINIT is not examined if the shell is a login 60 shell, or if it the shell is running a shell procedure. 61 62 63 647, March 1 65 66 67 68 69 70SH(1) 1991 SH(1) 71 72 73 (A shell is considered to be running a shell procedure if 74 neither the --ss nor the --cc options are set.) 75 76 CCoonnttrrooll SSttrruuccttuurreess 77 78 A _l_i_s_t is a sequence of zero or more commands separated by 79 newlines, semicolons, or ampersands, and optionally 80 terminated by one of these three characters. (This 81 differs from the System V shell, which requires a list to 82 contain at least one command in most cases.) The commands 83 in a list are executed in the order they are written. If 84 command is followed by an ampersand, the shell starts the 85 command and immediately proceed onto the next command; 86 otherwise it waits for the command to terminate before 87 proceeding to the next one. 88 89 ``&&'' and ``||'' are binary operators. ``&&'' executes 90 the first command, and then executes the second command 91 iff the exit status of the first command is zero. ``||'' 92 is similar, but executes the second command iff the exit 93 status of the first command is nonzero. ``&&'' and ``||'' 94 both have the same priority. 95 96 The ``|'' operator is a binary operator which feeds the 97 standard output of the first command into the standard 98 input of the second command. The exit status of the ``|'' 99 operator is the exit status of the second command. ``|'' 100 has a higher priority than ``||'' or ``&&''. 101 102 An _i_f command looks like 103 104 iiff list 105 tthheenn list 106 [ eelliiff list 107 tthheenn list ] ... 108 [ eellssee list ] 109 ffii 110 111 112 A _w_h_i_l_e command looks like 113 114 wwhhiillee list 115 ddoo list 116 ddoonnee 117 118 The two lists are executed repeatedly while the exit 119 status of the first list is zero. The _u_n_t_i_l command is 120 similar, but has the word uunnttiill in place of wwhhiillee 121 repeats until the exit status of the first list is zero. 122 123 The _f_o_r command looks like 124 125 ffoorr variable iinn word... 126 ddoo list 127 128 129 1307, March 2 131 132 133 134 135 136SH(1) 1991 SH(1) 137 138 139 ddoonnee 140 141 The words are expanded, and then the list is executed 142 repeatedly with the variable set to each word in turn. ddoo 143 and ddoonnee may be replaced with ``{'' and ``}''. 144 145 The _b_r_e_a_k and _c_o_n_t_i_n_u_e commands look like 146 147 bbrreeaakk [ num ] 148 ccoonnttiinnuuee [ num ] 149 150 _B_r_e_a_k terminates the _n_u_m innermost _f_o_r or _w_h_i_l_e loops. 151 _C_o_n_t_i_n_u_e continues with the next iteration of the _n_u_m'_t_h 152 innermost loop. These are implemented as builtin 153 commands. 154 155 The _c_a_s_e command looks like 156 157 ccaassee word iinn 158 pattern)) list ;;;; 159 ... 160 eessaacc 161 162 The pattern can actually be one or more patterns (see 163 _P_a_t_t_e_r_n_s below), separated by ``|'' characters. 164 165 Commands may be grouped by writing either 166 167 ((list)) 168 169 or 170 171 {{ list; }} 172 173 The first of these executes the commands in a subshell. 174 175 A function definition looks like 176 177 name (( )) command 178 179 A function definition is an executable statement; when 180 executed it installs a function named nnaammee and returns an 181 exit status of zero. The command is normally a list 182 enclosed between ``{'' and ``}''. 183 184 Variables may be declared to be local to a function by 185 using a _l_o_c_a_l command. This should appear as the first 186 staement of a function, and looks like 187 188 llooccaall [ variable | -- ] ... 189 190 _L_o_c_a_l is implemented as a builtin command. 191 192 When a variable is made local, it inherits the initial 193 194 195 1967, March 3 197 198 199 200 201 202SH(1) 1991 SH(1) 203 204 205 value and exported and readonly flags from the variable 206 with the same name in the surrounding scope, if there is 207 one. Otherwise, the variable is initially unset. _A_s_h 208 uses dynamic scoping, so that if you make the variable xx 209 local to function _f, which then calls function _g, 210 references to the variable xx made inside _g will refer to 211 the variable xx declared inside _f, not to the global 212 variable named xx. 213 214 The only special parameter than can be made local is 215 ``--''. Making ``--'' local any shell options that are 216 changed via the _s_e_t command inside the function to be 217 restored to their original values when the function 218 returns. 219 220 The _r_e_t_u_r_n command looks like 221 222 rreettuurrnn [ exitstatus ] 223 224 It terminates the currently executing function. _R_e_t_u_r_n is 225 implemented as a builtin command. 226 227 SSiimmppllee CCoommmmaannddss 228 229 A simple command is a sequence of words. The execution of 230 a simple command proceeds as follows. First, the leading 231 words of the form ``name=value'' are stripped off and 232 assigned to the environment of the command. Second, the 233 words are expanded. Third, the first remaining word is 234 taken as the command name that command is located. 235 Fourth, any redirections are performed. Fifth, the 236 command is executed. We look at these operations in 237 reverse order. 238 239 The execution of the command varies with the type of 240 command. There are three types of commands: shell 241 functions, builtin commands, and normal programs. 242 243 When a shell function is executed, all of the shell 244 positional parameters (except $0, which remains unchanged) 245 are set to the parameters to the shell function. The 246 variables which are explicitly placed in the environment 247 of the command (by placing assignments to them before the 248 function name) are made local to the function and are set 249 to values given. Then the command given in the function 250 definition is executed. The positional parameters are 251 restored to their original values when the command 252 completes. 253 254 Shell builtins are executed internally to the shell, 255 without spawning a new process. 256 257 When a normal program is executed, the shell runs the 258 program, passing the parameters and the environment to the 259 260 261 2627, March 4 263 264 265 266 267 268SH(1) 1991 SH(1) 269 270 271 program. If the program is a shell procedure, the shell 272 will interpret the program in a subshell. The shell will 273 reinitialize itself in this case, so that the effect will 274 be as if a new shell had been invoked to handle the shell 275 procedure, except that the location of commands located in 276 the parent shell will be remembered by the child. If the 277 program is a file beginning with ``#!'', the remainder of 278 the first line specifies an interpreter for the program. 279 The shell (or the operating system, under Berkeley UNIX) 280 will run the interpreter in this case. The arguments to 281 the interpreter will consist of any arguments given on the 282 first line of the program, followed by the name of the 283 program, followed by the arguments passed to the program. 284 285 RReeddiirreeccttiioonn 286 287 Input/output redirections can be intermixed with the words 288 in a simple command and can be placed following any of the 289 other commands. When redirection occurs, the shell saves 290 the old values of the file descriptors and restores them 291 when the command completes. The ``<'', ``>'', and ``>>'' 292 redirections open a file for input, output, and appending, 293 respectively. The ``<&digit'' and ``>&digit'' makes the 294 input or output a duplicate of the file descriptor 295 numbered by the digit. If a minus sign is used in place 296 of a digit, the standard input or standard output are 297 closed. 298 299 The ``<< word'' redirection takes input from a _h_e_r_e 300 document. As the shell encounters ``<<'' redirections, it 301 collects them. The next time it encounters an unescaped 302 newline, it reads the documents in turn. The word 303 following the ``<<'' specifies the contents of the line 304 that terminates the document. If none of the quoting 305 methods ('', "", or \) are used to enter the word, then 306 the document is treated like a word inside double quotes: 307 ``$'' and backquote are expanded and backslash can be used 308 to escape these and to continue long lines. The word 309 cannot contain any variable or command substitutions, and 310 its length (after quoting) must be in the range of 1 to 79 311 characters. If ``<<-'' is used in place of ``<<'', then 312 leading tabs are deleted from the lines of the document. 313 (This is to allow you do indent shell procedures 314 containing here documents in a natural fashion.) 315 316 Any of the preceding redirection operators may be preceded 317 by a single digit specifying the file descriptor to be 318 redirected. There cannot be any white space between the 319 digit and the redirection operator. 320 321 PPaatthh SSeeaarrcchh 322 323 When locating a command, the shell first looks to see if 324 it has a shell function by that name. Then, if PATH does 325 326 327 3287, March 5 329 330 331 332 333 334SH(1) 1991 SH(1) 335 336 337 not contain an entry for "%builtin", it looks for a 338 builtin command by that name. Finally, it searches each 339 entry in PATH in turn for the command. 340 341 The value of the PATH variable should be a series of 342 entries separated by colons. Each entry consists of a 343 directory name, or a directory name followed by a flag 344 beginning with a percent sign. The current directory 345 should be indicated by an empty directory name. 346 347 If no percent sign is present, then the entry causes the 348 shell to search for the command in the specified 349 directory. If the flag is ``%builtin'' then the list of 350 shell builtin commands is searched. If the flag is 351 ``%func'' then the directory is searched for a file which 352 is read as input to the shell. This file should define a 353 function whose name is the name of the command being 354 searched for. 355 356 Command names containing a slash are simply executed 357 without performing any of the above searches. 358 359 TThhee EEnnvviirroonnmmeenntt 360 361 The environment of a command is a set of name/value pairs. 362 When the shell is invoked, it reads these names and 363 values, sets the shell variables with these names to the 364 corresponding values, and marks the variables as exported. 365 The _e_x_p_o_r_t command can be used to mark additional 366 variables as exported. 367 368 The environment of a command is constructed by 369 constructing name/value pairs from all the exported shell 370 variables, and then modifying this set by the assignments 371 which precede the command, if any. 372 373 EExxppaannssiioonn 374 375 The process of evaluating words when a shell procedure is 376 executed is called _e_x_p_a_n_s_i_o_n. Expansion consists of four 377 steps: variable substitution, command substitution, word 378 splitting, and file name generation. If a word is the 379 expression following the word ccaassee in a case statement, 380 the file name which follows a redirection symbol, or an 381 assignment to the environment of a command, then the word 382 cannot be split into multiple words. In these cases, the 383 last two steps of the expansion process are omitted. 384 385 VVaarriiaabbllee SSuubbssttiittuuttiioonn 386 387 To be written. 388 389 CCoommmmaanndd SSuubbssttiittuuttiioonn 390 391 392 393 3947, March 6 395 396 397 398 399 400SH(1) 1991 SH(1) 401 402 403 _A_s_h accepts two syntaxes for command substitution: 404 405 ``_l_i_s_t` 406 407 and 408 409 $$((_l_i_s_t) 410 411 Either of these may be included in a word. During the 412 command substitution process, the command (syntactly a 413 _l_i_s_t) will be executed and anything that the command 414 writes to the standard output will be captured by the 415 shell. The final newline (if any) of the output will be 416 deleted; the rest of the output will be substituted for 417 the command in the word. 418 419 WWoorrdd SSpplliittttiinngg 420 421 When the value of a variable or the output of a command is 422 substituted, the resulting text is subject to word 423 splitting, unless the dollar sign introducing the variable 424 or backquotes containing the text were enclosed in double 425 quotes. In addition, ``$@'' is subject to a special type 426 of splitting, even in the presence of double quotes. 427 428 Ash uses two different splitting algorithms. The normal 429 approach, which is intended for splitting text separated 430 by which space, is used if the first character of the 431 shell variable IFS is a space. Otherwise an alternative 432 experimental algorithm, which is useful for splitting 433 (possibly empty) fields separated by a separator 434 character, is used. 435 436 When performing splitting, the shell scans the replacement 437 text looking for a character (when IFS does not begin with 438 a space) or a sequence of characters (when IFS does begin 439 with a space), deletes the character or sequence of 440 characters, and spits the word into two strings at that 441 point. When IFS begins with a space, the shell deletes 442 either of the strings if they are null. As a special 443 case, if the word containing the replacement text is the 444 null string, the word is deleted. 445 446 The variable ``$@'' is special in two ways. First, 447 splitting takes place between the positional parameters, 448 even if the text is enclosed in double quotes. Second, if 449 the word containing the replacement text is the null 450 string and there are no positional parameters, then the 451 word is deleted. The result of these rules is that "$@" 452 is equivalent to "$1" "$2" ... "$_n", where _n is the number 453 of positional parameters. (Note that this differs from 454 the System V shell. The System V documentation claims 455 that "$@" behaves this way; in fact on the System V shell 456 "$@" is equivalent to "" when there are no positional 457 458 459 4607, March 7 461 462 463 464 465 466SH(1) 1991 SH(1) 467 468 469 paramteters.) 470 471 FFiillee NNaammee GGeenneerraattiioonn 472 473 Unless the --ff flag is set, file name generation is 474 performed after word splitting is complete. Each word is 475 viewed as a series of patterns, separated by slashes. The 476 process of expansion replaces the word with the names of 477 all existing files whose names can be formed by replacing 478 each pattern with a string that matches the specified 479 pattern. There are two restrictions on this: first, a 480 pattern cannot match a string containing a slash, and 481 second, a pattern cannot match a string starting with a 482 period unless the first character of the pattern is a 483 period. 484 485 If a word fails to match any files and the --zz flag is not 486 set, then the word will be left unchanged (except that the 487 meta-characters will be converted to normal characters). 488 If the --zz flag is set, then the word is only left 489 unchanged if none of the patterns contain a character that 490 can match anything besides itself. Otherwise the --zz flag 491 forces the word to be replaced with the names of the files 492 that it matches, even if there are zero names. 493 494 PPaatttteerrnnss 495 496 A _p_a_t_t_e_r_n consists of normal characters, which match 497 themselves, and meta-characters. The meta-characters are 498 ``!'', ``*'', ``?'', and ``[''. These characters lose 499 there special meanings if they are quoted. When command 500 or variable substitution is performed and the dollar sign 501 or back quotes are not double quoted, the value of the 502 variable or the output of the command is scanned for these 503 characters and they are turned into meta-characters. 504 505 Two exclamation points at the beginning of a pattern 506 function as a ``not'' operator, causing the pattern to 507 match any string that the remainder of the pattern does 508 _n_o_t match. Other occurances of exclamation points in a 509 pattern match exclamation points. Two exclamation points 510 are required rather than one to decrease the 511 incompatibility with the System V shell (which does not 512 treat exclamation points specially). 513 514 An asterisk (``*'') matches any string of characters. A 515 question mark matches any single character. A left 516 bracket (``['') introduces a character class. The end of 517 the character class is indicated by a ``]''; if the ``]'' 518 is missing then the ``['' matches a ``['' rather than 519 introducing a character class. A character class matches 520 any of the characters between the square brackets. A 521 range of characters may be specified using a minus sign. 522 The character class may be complemented by making an 523 524 525 5267, March 8 527 528 529 530 531 532SH(1) 1991 SH(1) 533 534 535 exclamation point the first character of the character 536 class. 537 538 To include a ``]'' in a character class, make it the first 539 character listed (after the ``!'', if any). To include a 540 minus sign, make it the first or last character listed. 541 542 TThhee //uu DDiirreeccttoorryy 543 544 By convention, the name ``/u/user'' refers to the home 545 directory of the specified user. There are good reasons 546 why this feature should be supported by the file system 547 (using a feature such as symbolic links) rather than by 548 the shell, but _a_s_h is capable of performing this mapping 549 if the file system doesn't. If the mapping is done by 550 _a_s_h, setting the --ff flag will turn it off. 551 552 CChhaarraacctteerr SSeett 553 554 _A_s_h silently discards nul characters. Any other character 555 will be handled correctly by _a_s_h, including characters 556 with the high order bit set. 557 558 JJoobb NNaammeess aanndd JJoobb CCoonnttrrooll 559 560 The term _j_o_b refers to a process created by a shell 561 command, or in the case of a pipeline, to the set of 562 processes in the pipeline. The ways to refer to a job 563 are: 564 565 %%_n_u_m_b_e_r %_s_t_r_i_n_g %% _p_r_o_c_e_s_s__i_d 566 567 The first form identifies a job by job number. When a 568 command is run, _a_s_h assigns it a job number (the lowest 569 unused number is assigned). The second form identifies a 570 job by giving a prefix of the command used to create the 571 job. The prefix must be unique. If there is only one 572 job, then the null prefix will identify the job, so you 573 can refer to the job by writing ``%''. The third form 574 refers to the _c_u_r_r_e_n_t _j_o_b. The current job is the last 575 job to be stopped while it was in the foreground. (See 576 the next paragraph.) The last form identifies a job by 577 giving the process id of the last process in the job. 578 579 If the operating system that _a_s_h is running on supports 580 job control, _a_s_h will allow you to use it. In this case, 581 typing the suspend character (typically ^Z) while running 582 a command will return you to _a_s_h and will make the 583 suspended command the current job. You can then continue 584 the job in the background by typing _b_g, or you can 585 continue it in the foreground by typing _f_g. 586 587 AAttttyy 588 589 590 591 5927, March 9 593 594 595 596 597 598SH(1) 1991 SH(1) 599 600 601 If the shell variable ATTY is set, and the shell variable 602 TERM is not set to ``emacs'', then _a_s_h generates 603 appropriate escape sequences to talk to _a_t_t_y(1). 604 605 EExxiitt SSttaattuusseess 606 607 By tradition, an exit status of zero means that a command 608 has succeeded and a nonzero exit status indicates that the 609 command failed. This is better than no convention at all, 610 but in practice it is extremely useful to allow commands 611 that succeed to use the exit status to return information 612 to the caller. A variety of better conventions have been 613 proposed, but none of them has met with universal 614 approval. The convention used by _a_s_h and all the programs 615 included in the _a_s_h distribution is as follows: 616 0 Success. 617 1 Alternate success. 618 2 Failure. 619 129-... Command terminated by a signal. 620 The _a_l_t_e_r_n_a_t_e _s_u_c_c_e_s_s return is used by commands to 621 indicate various conditions which are not errors but which 622 can, with a little imagination, be conceived of as less 623 successful than plain success. For example, _t_e_s_t returns 624 1 when the tested condition is false and _g_e_t_o_p_t_s returns 1 625 when there are no more options. Because this convention 626 is not used universally, the --ee option of _a_s_h causes the 627 shell to exit when a command returns 1 even though that 628 contradicts the convention described here. 629 630 When a command is terminated by a signal, the uses 128 631 plus the signal number as the exit code for the command. 632 633 BBuuiillttiinn CCoommmmaannddss 634 635 This concluding section lists the builtin commands which 636 are builtin because they need to perform some operation 637 that can't be performed by a separate process. In 638 addition to these, there are several other commands (_c_a_t_f, 639 _e_c_h_o, _e_x_p_r, _l_i_n_e, _n_l_e_c_h_o, _t_e_s_t, ``:'', and _t_r_u_e) which can 640 optionally be compiled into the shell. The builtin 641 commands described below that accept options use the 642 System V Release 2 _g_e_t_o_p_t(3) syntax. 643 644 645 bbgg [ _j_o_b ] ... 646 Continue the specified jobs (or the current job if no 647 jobs are given) in the background. This command is 648 only available on systems with Bekeley job control. 649 650 bbllttiinn _c_o_m_m_a_n_d _a_r_g... 651 Execute the specified builtin command. (This is 652 useful when you have a shell function with the same 653 name as a builtin command.) 654 655 656 657 6587, March 10 659 660 661 662 663 664SH(1) 1991 SH(1) 665 666 667 ccdd [ _d_i_r_e_c_t_o_r_y ] 668 Switch to the specified directory (default $HOME). 669 If the an entry for CDPATH appears in the environment 670 of the cd command or the shell variable CDPATH is set 671 and the directory name does not begin with a slash, 672 then the directories listed in CDPATH will be 673 searched for the specified directory. The format of 674 CDPATH is the same as that of PATH. In an 675 interactive shell, the cd command will print out the 676 name of the directory that it actually switched to if 677 this is different from the name that the user gave. 678 These may be different either because the CDPATH 679 mechanism was used or because a symbolic link was 680 crossed. 681 682 .. _f_i_l_e 683 The commands in the specified file are read and 684 executed by the shell. A path search is not done to 685 find the file because the directories in PATH 686 generally contain files that are intended to be 687 executed, not read. 688 689 eevvaall _s_t_r_i_n_g... 690 The strings are parsed as shell commands and 691 executed. (This differs from the System V shell, 692 which concatenates the arguments (separated by 693 spaces) and parses the result as a single command.) 694 695 eexxeecc [ _c_o_m_m_a_n_d _a_r_g... ] 696 Unless _c_o_m_m_a_n_d is omitted, the shell process is 697 replaced with the specified program (which must be a 698 real program, not a shell builtin or function). Any 699 redirections on the exec command are marked as 700 permanent, so that they are not undone when the exec 701 command finishes. If the command is not found, the 702 exec command causes the shell to exit. 703 704 eexxiitt [ _e_x_i_t_s_t_a_t_u_s ] 705 Terminate the shell process. If _e_x_i_t_s_t_a_t_u_s is given 706 it is used as the exit status of the shell; otherwise 707 the exit status of the preceding command is used. 708 709 eexxppoorrtt _n_a_m_e... 710 The specified names are exported so that they will 711 appear in the environment of subsequent commands. 712 The only way to un-export a variable is to unset it. 713 _A_s_h allows the value of a variable to be set at the 714 same time it is exported by writing 715 716 eexxppoorrtt name=value 717 718 With no arguments the export command lists the names 719 of all exported variables. 720 721 722 723 7247, March 11 725 726 727 728 729 730SH(1) 1991 SH(1) 731 732 733 ffgg [ _j_o_b ] 734 Move the specified job or the current job to the 735 foreground. This command is only available on 736 systems with Bekeley job control. 737 738 ggeettooppttss _o_p_t_s_t_r_i_n_g _v_a_r 739 The System V _g_e_t_o_p_t_s command. 740 741 hhaasshh --rrvv _c_o_m_m_a_n_d... 742 The shell maintains a hash table which remembers the 743 locations of commands. With no arguments whatsoever, 744 the hash command prints out the contents of this 745 table. Entries which have not been looked at since 746 the last _c_d command are marked with an asterisk; it 747 is possible for these entries to be invalid. 748 749 With arguments, the hash command removes the 750 specified commands from the hash table (unless they 751 are functions) and then locates them. With the --vv 752 option, _h_a_s_h prints the locations of the commands as 753 it finds them. The --rr option causes the _h_a_s_h command 754 to delete all the entries in the hash table except 755 for functions. 756 757 jjoobbiidd [ _j_o_b ] 758 Print the process id's of the processes in the job. 759 If the job argument is omitted, use the current job. 760 761 jjoobbss 762 This command lists out all the background processes 763 which are children of the current shell process. 764 765 llcc [ _f_u_n_c_t_i_o_n-_n_a_m_e ] 766 The function name is defined to execute the last 767 command entered. If the function name is omitted, 768 the last command executed is executed again. This 769 command only works if the --ii flag is set. 770 771 ppwwdd 772 Print the current directory. The builtin command may 773 differ from the program of the same name because the 774 builtin command remembers what the current directory 775 is rather than recomputing it each time. This makes 776 it faster. However, if the current directory is 777 renamed, the builtin version of pwd will continue to 778 print the old name for the directory. 779 780 rreeaadd [ --pp _p_r_o_m_p_t ] [ --ee ] _v_a_r_i_a_b_l_e... 781 The prompt is printed if the --pp option is specified 782 and the standard input is a terminal. Then a line is 783 read from the standard input. The trailing newline 784 is deleted from the line and the line is split as 785 described in the section on word splitting above, and 786 the pieces are assigned to the variables in order. 787 788 789 7907, March 12 791 792 793 794 795 796SH(1) 1991 SH(1) 797 798 799 If there are more pieces than variables, the 800 remaining pieces (along with the characters in IFS 801 that separated them) are assigned to the last 802 variable. If there are more variables than pieces, 803 the remaining variables are assigned the null string. 804 805 The --ee option causes any backslashes in the input to 806 be treated specially. If a backslash is followed by 807 a newline, the backslash and the newline will be 808 deleted. If a backslash is followed by any other 809 character, the backslash will be deleted and the 810 following character will be treated as though it were 811 not in IFS, even if it is. 812 813 rreeaaddoonnllyy _n_a_m_e... 814 The specified names are marked as read only, so that 815 they cannot be subsequently modified or unset. _A_s_h 816 allows the value of a variable to be set at the same 817 time it is marked read only by writing 818 819 rreeaaddoonnllyy name=value 820 821 With no arguments the readonly command lists the 822 names of all read only variables. 823 824 sseett [ { --_o_p_t_i_o_n_s | ++_o_p_t_i_o_n_s | ---- } ] _a_r_g... 825 The _s_e_t command performs three different functions. 826 827 With no arguments, it lists the values of all shell 828 variables. 829 830 If options are given, it sets the specified option 831 flags, or clears them if the option flags are 832 introduced with a ++ rather than a --. Only the first 833 argument to _s_e_t can contain options. The possible 834 options are: 835 836 --ee Causes the shell to exit when a command 837 terminates with a nonzero exit status, except 838 when the exit status of the command is explicitly 839 tested. The exit status of a command is 840 considered to be explicitly tested if the command 841 is used to control an _i_f, _e_l_i_f, _w_h_i_l_e, or _u_n_t_i_l; 842 or if the command is the left hand operand of an 843 ``&&'' or ``||'' operator. 844 845 --ff Turn off file name generation. 846 847 --II Cause the shell to ignore end of file conditions. 848 (This doesn't apply when the shell a script 849 sourced using the ``.'' command.) The shell 850 will in fact exit if it gets 50 eof's in a row. 851 852 --ii Make the shell interactive. This causes the 853 854 855 8567, March 13 857 858 859 860 861 862SH(1) 1991 SH(1) 863 864 865 shell to prompt for input, to trap interrupts, to 866 ignore quit and terminate signals, and to return 867 to the main command loop rather than exiting on 868 error. 869 870 --jj Turns on Berkeley job control, on systems that 871 support it. When the shell starts up, the --jj is 872 set by default if the --ii flag is set. 873 874 --nn Causes the shell to read commands but not execute 875 them. (This is marginally useful for checking 876 the syntax of scripts.) 877 878 --ss If this flag is set when the shell starts up, the 879 shell reads commands from its standard input. 880 The shell doesn't examine the value of this flag 881 any other time. 882 883 --xx If this flag is set, the shell will print out 884 each command before executing it. 885 886 --zz If this flag is set, the file name generation 887 process may generate zero files. If it is not 888 set, then a pattern which does not match any 889 files will be replaced by a quoted version of the 890 pattern. 891 892 The third use of the set command is to set the values 893 of the shell's positional parameters to the specified 894 _a_r_g_s. To change the positional parameters without 895 changing any options, use ``----'' as the first 896 argument to _s_e_t. If no args are present, the set 897 command will leave the value of the positional 898 parameters unchanged, so to set the positional 899 parameters to set of values that may be empty, 900 execute the command 901 902 shift $# 903 904 first to clear out the old values of the positional 905 parameters. 906 907 sseettvvaarr _v_a_r_i_a_b_l_e _v_a_l_u_e 908 Assigns _v_a_l_u_e to _v_a_r_i_a_b_l_e. (In general it is better 909 to write _v_a_r_i_a_b_l_e=_v_a_l_u_e rather than using _s_e_t_v_a_r. 910 _S_e_t_v_a_r is intended to be used in functions that 911 assign values to variables whose names are passed as 912 parameters.) 913 914 sshhiifftt [ _n ] 915 Shift the positional parameters _n times. A shift 916 sets the value of $1 to the value of $2, the value of 917 $2 to the value of $3, and so on, decreasing the 918 value of $# by one. If there are zero positional 919 920 921 9227, March 14 923 924 925 926 927 928SH(1) 1991 SH(1) 929 930 931 parameters, shifting doesn't do anything. 932 933 ttrraapp [ _a_c_t_i_o_n ] _s_i_g_n_a_l... 934 Cause the shell to parse and execute _a_c_t_i_o_n when any 935 of the specified signals are received. The signals 936 are specified by signal number. _A_c_t_i_o_n may be null 937 or omitted; the former causes the specified signal to 938 be ignored and the latter causes the default action 939 to be taken. When the shell forks off a subshell, it 940 resets trapped (but not ignored) signals to the 941 default action. The trap command has no effect on 942 signals that were ignored on entry to the shell. 943 944 uummaasskk [ _m_a_s_k ] 945 Set the value of umask (see _u_m_a_s_k(2)) to the 946 specified octal value. If the argument is omitted, 947 the umask value is printed. 948 949 uunnsseett _n_a_m_e... 950 The specified variables and functions are unset and 951 unexported. If a given name corresponds to both a 952 variable and a function, both the variable and the 953 function are unset. 954 955 wwaaiitt [ _j_o_b ] 956 Wait for the specified job to complete and return the 957 exit status of the last process in the job. If the 958 argument is omitted, wait for all jobs to complete 959 and the return an exit status of zero. 960 961EEXXAAMMPPLLEESS 962 The following function redefines the _c_d command: 963 964 cd() { 965 if bltin cd "$@" 966 thenif test -f .enter 967 then. .enter 968 elsereturn 0 969 fi 970 fi 971 } 972 973 This function causes the file ``.enter'' to be read when 974 you enter a directory, if it exists. The _b_l_t_i_n command is 975 used to access the real _c_d command. The ``return 0'' 976 ensures that the function will return an exit status of 977 zero if it successfully changes to a directory that does 978 not contain a ``.enter'' file. Redefining existing 979 commands is not always a good idea, but this example shows 980 that you can do it if you want to. 981 982 The suspend function distributed with _a_s_h looks like 983 984 # Copyright (C) 1989 by Kenneth Almquist. All rights reserved. 985 986 987 9887, March 15 989 990 991 992 993 994SH(1) 1991 SH(1) 995 996 997 # This file is part of ash, which is distributed under the terms 998 # specified by the Ash General Public License. 999 1000 suspend() { 1001 local - 1002 set +j 1003 kill -TSTP 0 1004 } 1005 1006 This turns off job control and then sends a stop signal to 1007 the current process group, which suspends the shell. 1008 (When job control is turned on, the shell ignores the TSTP 1009 signal.) Job control will be turned back on when the 1010 function returns because ``-'' is local to the function. 1011 As an example of what _n_o_t to do, consider an earlier 1012 version of _s_u_s_p_e_n_d: 1013 1014 suspend() { 1015 suspend_flag=$- 1016 set +j 1017 kill -TSTP 0 1018 set -$suspend_flag 1019 } 1020 1021 There are two problems with this. First, ssuussppeenndd__ffllaagg is 1022 a global variable rather than a local one, which will 1023 cause problems in the (unlikely) circumstance that the 1024 user is using that variable for some other purpose. 1025 Second, consider what happens if shell received an 1026 interrupt signal after it executes the first _s_e_t command 1027 but before it executes the second one. The interrupt 1028 signal will abort the shell function, so that the second 1029 _s_e_t command will never be executed and job control will be 1030 left off. The first version of _s_u_s_p_e_n_d avoids this 1031 problem by turning job control off only in a local copy of 1032 the shell options. The local copy of the shell options is 1033 discarded when the function is terminated, no matter how 1034 it is terminated. 1035 1036HHIINNTTSS 1037 Shell variables can be used to provide abbreviations for 1038 things which you type frequently. For example, I set 1039 export h=$HOME 1040 in my .profile so that I can type the name of my home 1041 directory simply by typing ``$h''. 1042 1043 When writing shell procedures, try not to make assumptions 1044 about what is imported from the environment. Explicitly 1045 unset or initialize all variables, rather than assuming 1046 they will be unset. If you use cd, it is a good idea to 1047 unset CDPATH. 1048 1049 People sometimes use ``<&-'' or ``>&-'' to provide no 1050 input to a command or to discard the output of a command. 1051 1052 1053 10547, March 16 1055 1056 1057 1058 1059 1060SH(1) 1991 SH(1) 1061 1062 1063 A better way to do this is to redirect the input or output 1064 of the command to //ddeevv//nnuullll. 1065 1066 Word splitting and file name generation are performed by 1067 default, and you have to explicitly use double quotes to 1068 suppress it. This is backwards, but you can learn to live 1069 with it. Just get in the habit of writing double quotes 1070 around variable and command substitutions, and omit them 1071 only when you really want word splitting and file name 1072 generation. If you want word splitting but not file name 1073 generation, use the --ff option. 1074 1075AAUUTTHHOORRSS 1076 Kenneth Almquist 1077 1078SSEEEE AALLSSOO 1079 echo(1), expr(1), line(1), pwd(1), true(1). 1080 1081BBUUGGSS 1082 When command substitution occurs inside a here document, 1083 the commands inside the here document are run with their 1084 standard input closed. For example, the following will 1085 not word because the standard input of the _l_i_n_e command 1086 will be closed when the command is run: 1087 1088 cat <<-! 1089 Line 1: $(line) 1090 Line 2: $(line) 1091 ! 1092 1093 1094 Unsetting a function which is currently being executed may 1095 cause strange behavior. 1096 1097 The shell syntax allows a here document to be terminated 1098 by an end of file as well as by a line containing the 1099 terminator word which follows the ``<<''. What this means 1100 is that if you mistype the terminator line, the shell will 1101 silently swallow up the rest of your shell script and 1102 stick it in the here document. 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 11207, March 17 1121 1122 1123