1CSH(1) 386BSD Reference Manual CSH(1) 2 3NNAAMMEE 4 ccsshh - a shell (command interpreter) with C-like syntax 5 6SSYYNNOOPPSSIISS 7 ccsshh [--bbcceeffiinnssttvvVVxxXX] [arg ...] 8 9DDEESSCCRRIIPPTTIIOONN 10 The CCsshh is a command language interpreter incorporating a history 11 mechanism (see HHiissttoorryy SSuubbssttiittuuttiioonnss), job control facilities (see JJoobbss), 12 interactive file name and user name completion (see FFiillee NNaammee 13 CCoommpplleettiioonn), and a C-like syntax. It is used both as an interactive login 14 shell and a shell script command processor. 15 16 AArrgguummeenntt lliisstt pprroocceessssiinngg 17 If the first argument (argument 0) to the shell is `--' then this is a 18 login shell. The flag arguments are interpreted as follows: 19 20 --bb This flag forces a ``break'' from option processing, causing any 21 further shell arguments to be treated as non-option arguments. 22 The remaining arguments will not be interpreted as shell options. 23 This may be used to pass options to a shell script without 24 confusion or possible subterfuge. The shell will not run a set- 25 user ID script without this option. 26 27 --cc Commands are read from the (single) following argument which must 28 be present. Any remaining arguments are placed in _a_r_g_v. 29 30 --ee The shell exits if any invoked command terminates abnormally or 31 yields a non-zero exit status. 32 33 --ff The shell will start faster, because it will neither search for 34 nor execute commands from the file ._c_s_h_r_c in the invoker's home 35 directory. 36 37 --ii The shell is interactive and prompts for its top-level input, even 38 if it appears to not be a terminal. Shells are interactive 39 without this option if their inputs and outputs are terminals. 40 41 --nn Commands are parsed, but not executed. This aids in syntactic 42 checking of shell scripts. 43 44 --ss Command input is taken from the standard input. 45 46 --tt A single line of input is read and executed. A `\' may be used to 47 escape the newline at the end of this line and continue onto 48 another line. 49 50 --vv Causes the _v_e_r_b_o_s_e variable to be set, with the effect that 51 command input is echoed after history substitution. 52 53 --xx Causes the _e_c_h_o variable to be set, so that commands are echoed 54 immediately before execution. 55 56 --VV Causes the _v_e_r_b_o_s_e variable to be set even before ._c_s_h_r_c is 57 executed. 58 59 --XX Is to --xx as --VV is to --vv. 60 61 After processing of flag arguments, if arguments remain but none of the 62 --cc, --ii, --ss, or --tt options were given, the first argument is taken as the 63 name of a file of commands to be executed. The shell opens this file, 64 and saves its name for possible resubstitution by `$0'. Since many 65 systems use either the standard version 6 or version 7 shells whose shell 66 scripts are not compatible with this shell, the shell will execute such a 67 `standard' shell if the first character of a script is not a `#', i.e. if 68 the script does not start with a comment. Remaining arguments initialize 69 the variable _a_r_g_v. 70 71 An instance of ccsshh begins by executing commands from the file 72 /_e_t_c/_c_s_h._c_s_h_r_c and, if this is a login shell, /_e_t_c/_c_s_h._l_o_g_i_n. It then 73 executes commands from ._c_s_h_r_c in the _h_o_m_e directory of the invoker, and, 74 if this is a login shell, the file ._l_o_g_i_n in the same location. It is 75 typical for users on crt's to put the command ``stty crt'' in their 76 ._l_o_g_i_n file, and to also invoke tset(1) there. 77 78 In the normal case, the shell will begin reading commands from the 79 terminal, prompting with `% '. Processing of arguments and the use of 80 the shell to process files containing command scripts will be described 81 later. 82 83 The shell repeatedly performs the following actions: a line of command 84 input is read and broken into _w_o_r_d_s. This sequence of words is placed on 85 the command history list and parsed. Finally each command in the current 86 line is executed. 87 88 When a login shell terminates it executes commands from the files ._l_o_g_o_u_t 89 in the user's _h_o_m_e directory and /_e_t_c/_c_s_h._l_o_g_o_u_t. 90 91 LLeexxiiccaall ssttrruuccttuurree 92 The shell splits input lines into words at blanks and tabs with the 93 following exceptions. The characters `&' `|' `;' `<' `>' `(' `)' form 94 separate words. If doubled in `&&', `||', `<<' or `>>' these pairs form 95 single words. These parser metacharacters may be made part of other 96 words, or prevented their special meaning, by preceding them with `\'. A 97 newline preceded by a `\' is equivalent to a blank. 98 99 Strings enclosed in matched pairs of quotations, `', ``' or `"', form 100 parts of a word; metacharacters in these strings, including blanks and 101 tabs, do not form separate words. These quotations have semantics to be 102 described subsequently. Within pairs of `'' or `"' characters a newline 103 preceded by a `\' gives a true newline character. 104 105 When the shell's input is not a terminal, the character `#' introduces a 106 comment which continues to the end of the input line. It is prevented 107 this special meaning when preceded by `\' and in quotations using ``', 108 `'', and `"'. 109 110 CCoommmmaannddss 111 A simple command is a sequence of words, the first of which specifies the 112 command to be executed. A simple command or a sequence of simple 113 commands separated by `|' characters forms a pipeline. The output of 114 each command in a pipeline is connected to the input of the next. 115 Sequences of pipelines may be separated by `;', and are then executed 116 sequentially. A sequence of pipelines may be executed without 117 immediately waiting for it to terminate by following it with an `&'. 118 119 Any of the above may be placed in `(' `)' to form a simple command (which 120 may be a component of a pipeline, etc.) It is also possible to separate 121 pipelines with `||' or `&&' indicating, as in the C language, that the 122 second is to be executed only if the first fails or succeeds 123 respectively. (See _E_x_p_r_e_s_s_i_o_n_s.) 124 125 JJoobbss 126 The shell associates a _j_o_b with each pipeline. It keeps a table of 127 current jobs, printed by the _j_o_b_s command, and assigns them small integer 128 numbers. When a job is started asynchronously with `&', the shell prints 129 a line which looks like: 130 131 [1] 1234 132 133 indicating that the job which was started asynchronously was job number 1 134 and had one (top-level) process, whose process id was 1234. 135 136 If you are running a job and wish to do something else you may hit the 137 key ^^ZZ (control-Z) which sends a STOP signal to the current job. The 138 shell will then normally indicate that the job has been `Stopped', and 139 print another prompt. You can then manipulate the state of this job, 140 putting it in the _b_a_c_k_g_r_o_u_n_d with the _b_g command, or run some other 141 commands and then eventually bring the job back into the foreground with 142 the _f_o_r_e_g_r_o_u_n_d command _f_g. A ^^ZZ takes effect immediately and is like an 143 interrupt in that pending output and unread input are discarded when it 144 is typed. There is another special key ^^YY which does not generate a STOP 145 signal until a program attempts to read(2) it. This can usefully be 146 typed ahead when you have prepared some commands for a job which you wish 147 to stop after it has read them. 148 149 A job being run in the background will stop if it tries to read from the 150 terminal. Background jobs are normally allowed to produce output, but 151 this can be disabled by giving the command ``stty tostop''. If you set 152 this tty option, then background jobs will stop when they try to produce 153 output like they do when they try to read input. 154 155 There are several ways to refer to jobs in the shell. The character `%' 156 introduces a job name. If you wish to refer to job number 1, you can 157 name it as `%1'. Just naming a job brings it to the foreground; thus 158 `%1' is a synonym for `fg %1', bringing job 1 back into the foreground. 159 Similarly saying `%1 &' resumes job 1 in the background. Jobs can also 160 be named by prefixes of the string typed in to start them, if these 161 prefixes are unambiguous, thus `%ex' would normally restart a suspended 162 ex(1) job, if there were only one suspended job whose name began with the 163 string `ex'. It is also possible to say `%?string' which specifies a job 164 whose text contains _s_t_r_i_n_g, if there is only one such job. 165 166 The shell maintains a notion of the current and previous jobs. In output 167 pertaining to jobs, the current job is marked with a `+' and the previous 168 job with a `-'. The abbreviation `%+' refers to the current job and `%-' 169 refers to the previous job. For close analogy with the syntax of the 170 _h_i_s_t_o_r_y mechanism (described below), `%%' is also a synonym for the 171 current job. 172 173 The job control mechanism requires that the stty(1) option nneeww be set. It 174 is an artifact from a _n_e_w implementation of the tty driver which allows 175 generation of interrupt characters from the keyboard to tell jobs to 176 stop. See stty(1) for details on setting options in the new tty driver. 177 178 SSttaattuuss rreeppoorrttiinngg 179 This shell learns immediately whenever a process changes state. It 180 normally informs you whenever a job becomes blocked so that no further 181 progress is possible, but only just before it prints a prompt. This is 182 done so that it does not otherwise disturb your work. If, however, you 183 set the shell variable _n_o_t_i_f_y, the shell will notify you immediately of 184 changes of status in background jobs. There is also a shell command 185 _n_o_t_i_f_y which marks a single process so that its status changes will be 186 immediately reported. By default _n_o_t_i_f_y marks the current process; 187 simply say `notify' after starting a background job to mark it. 188 189 When you try to leave the shell while jobs are stopped, you will be 190 warned that `You have stopped jobs.' You may use the _j_o_b_s command to see 191 what they are. If you do this or immediately try to exit again, the 192 shell will not warn you a second time, and the suspended jobs will be 193 terminated. 194 195 FFiillee NNaammee CCoommpplleettiioonn 196 When the file name completion feature is enabled by setting the shell 197 variable _f_i_l_e_c (see sseett), ccsshh will interactively complete file names and 198 user names from unique prefixes, when they are input from the terminal 199 followed by the escape character (the escape key, or control-[) For 200 example, if the current directory looks like 201 202 DSC.OLD bin cmd lib xmpl.c 203 DSC.NEW chaosnet cmtest mail xmpl.o 204 bench class dev mbox xmpl.out 205 206 and the input is 207 208 % vi ch<escape> 209 210 ccsshh will complete the prefix ``ch'' to the only matching file name 211 ``chaosnet'', changing the input line to 212 213 % vi chaosnet 214 215 However, given 216 217 % vi D<escape> 218 219 ccsshh will only expand the input to 220 221 % vi DSC. 222 223 and will sound the terminal bell to indicate that the expansion is 224 incomplete, since there are two file names matching the prefix ``D''. 225 226 If a partial file name is followed by the end-of-file character (usually 227 control-D), then, instead of completing the name, ccsshh will list all file 228 names matching the prefix. For example, the input 229 230 % vi D<control-D> 231 232 causes all files beginning with ``D'' to be listed: 233 234 DSC.NEW DSC.OLD 235 236 while the input line remains unchanged. 237 238 The same system of escape and end-of-file can also be used to expand 239 partial user names, if the word to be completed (or listed) begins with 240 the character ``~''. For example, typing 241 242 cd ~ro<escape> 243 244 may produce the expansion 245 246 cd ~root 247 248 The use of the terminal bell to signal errors or multiple matches can be 249 inhibited by setting the variable _n_o_b_e_e_p. 250 251 Normally, all files in the particular directory are candidates for name 252 completion. Files with certain suffixes can be excluded from 253 consideration by setting the variable _f_i_g_n_o_r_e to the list of suffixes to 254 be ignored. Thus, if _f_i_g_n_o_r_e is set by the command 255 256 % set fignore = (.o .out) 257 258 then typing 259 260 % vi x<escape> 261 262 would result in the completion to 263 264 265 % vi xmpl.c 266 267 ignoring the files "xmpl.o" and "xmpl.out". However, if the only 268 completion possible requires not ignoring these suffixes, then they are 269 not ignored. In addition, _f_i_g_n_o_r_e does not affect the listing of file 270 names by control-D. All files are listed regardless of their suffixes. 271 272 SSuubbssttiittuuttiioonnss 273 We now describe the various transformations the shell performs on the 274 input in the order in which they occur. 275 276 HHiissttoorryy ssuubbssttiittuuttiioonnss 277 History substitutions place words from previous command input as portions 278 of new commands, making it easy to repeat commands, repeat arguments of a 279 previous command in the current command, or fix spelling mistakes in the 280 previous command with little typing and a high degree of confidence. 281 History substitutions begin with the character `!' and may begin _a_n_y_w_h_e_r_e 282 in the input stream (with the proviso that they ddoo nnoott nest.) This `!' 283 may be preceded by an `\' to prevent its special meaning; for 284 convenience, a `!' is passed unchanged when it is followed by a blank, 285 tab, newline, `=' or `('. (History substitutions also occur when an 286 input line begins with `^'. This special abbreviation will be described 287 later.) Any input line which contains history substitution is echoed on 288 the terminal before it is executed as it could have been typed without 289 history substitution. 290 291 Commands input from the terminal which consist of one or more words are 292 saved on the history list. The history substitutions reintroduce 293 sequences of words from these saved commands into the input stream. The 294 size of which is controlled by the _h_i_s_t_o_r_y variable; the previous command 295 is always retained, regardless of its value. Commands are numbered 296 sequentially from 1. 297 298 For definiteness, consider the following output from the _h_i_s_t_o_r_y command: 299 300 9 write michael 301 10 ex write.c 302 11 cat oldwrite.c 303 12 diff *write.c 304 305 The commands are shown with their event numbers. It is not usually 306 necessary to use event numbers, but the current event number can be made 307 part of the _p_r_o_m_p_t by placing an `!' in the prompt string. 308 309 With the current event 13 we can refer to previous events by event number 310 `!11', relatively as in `!-2' (referring to the same event), by a prefix 311 of a command word as in `!d' for event 12 or `!wri' for event 9, or by a 312 string contained in a word in the command as in `!?mic?' also referring 313 to event 9. These forms, without further modification, simply 314 reintroduce the words of the specified events, each separated by a single 315 blank. As a special case `!!' refers to the previous command; thus `!!' 316 alone is essentially a _r_e_d_o. 317 318 To select words from an event we can follow the event specification by a 319 `:' and a designator for the desired words. The words of an input line 320 are numbered from 0, the first (usually command) word being 0, the second 321 word (first argument) being 1, etc. The basic word designators are: 322 323 0 first (command) word 324 _n _n'th argument 325 ^ first argument, i.e. `1' 326 $ last argument 327 % word matched by (immediately preceding) ?_s? search 328 329 330 _x-_y range of words 331 -_y abbreviates `_0-_y' 332 * abbreviates `^-$', or nothing if only 1 word in event 333 _x* abbreviates `_x-$' 334 _x- like `_x*' but omitting word `$' 335 336 The `:' separating the event specification from the word designator can 337 be omitted if the argument selector begins with a `^', `$', `*' `-' or 338 `%'. After the optional word designator can be placed a sequence of 339 modifiers, each preceded by a `:'. The following modifiers are defined: 340 341 h Remove a trailing pathname component, leaving the head. 342 r Remove a trailing `.xxx' component, leaving the root name. 343 e Remove all but the extension `.xxx' part. 344 s/_l/_r/ Substitute _l for _r 345 t Remove all leading pathname components, leaving the tail. 346 & Repeat the previous substitution. 347 g Apply the change globally, prefixing the above, e.g. `g&'. 348 p Print the new command line but do not execute it. 349 q Quote the substituted words, preventing further 350 substitutions. 351 x Like q, but break into words at blanks, tabs and newlines. 352 353 Unless preceded by a `g' the modification is applied only to the first 354 modifiable word. With substitutions, it is an error for no word to be 355 applicable. 356 357 The left hand side of substitutions are not regular expressions in the 358 sense of the editors, but rather strings. Any character may be used as 359 the delimiter in place of `/'; a `\' quotes the delimiter into the _l and 360 _r strings. The character `&' in the right hand side is replaced by the 361 text from the left. A `\' quotes `&' also. A null _l (" ") uses the 362 previous string either from a _l or from a contextual scan string _s in 363 `!?_s?'. The trailing delimiter in the substitution may be omitted if a 364 newline follows immediately as may the trailing `?' in a contextual scan. 365 366 A history reference may be given without an event specification, e.g. 367 `!$'. In this case the reference is to the previous command unless a 368 previous history reference occurred on the same line in which case this 369 form repeats the previous reference. Thus `!?foo?^ !$' gives the first 370 and last arguments from the command matching `?foo?'. 371 372 A special abbreviation of a history reference occurs when the first non- 373 blank character of an input line is a `^'. This is equivalent to `!:s^' 374 providing a convenient shorthand for substitutions on the text of the 375 previous line. Thus `^lb^lib' fixes the spelling of `lib' in the 376 previous command. Finally, a history substitution may be surrounded with 377 `{' and `}' if necessary to insulate it from the characters which follow. 378 Thus, after `ls -ld ~paul' we might do `!{l}a' to do `ls -ld ~paula', 379 while `!la' would look for a command starting `la'. 380 381 QQuuoottaattiioonnss wwiitthh '' aanndd "" 382 The quotation of strings by `'' and `"' can be used to prevent all or 383 some of the remaining substitutions. Strings enclosed in `'' are 384 prevented any further interpretation. Strings enclosed in `"' may be 385 expanded as described below. 386 387 In both cases the resulting text becomes (all or part of) a single word; 388 only in one special case (see _C_o_m_m_a_n_d _S_u_b_s_t_i_t_i_t_i_o_n below) does a `"' 389 quoted string yield parts of more than one word; `'' quoted strings never 390 do. 391 392 AAlliiaass ssuubbssttiittuuttiioonn 393 The shell maintains a list of aliases which can be established, displayed 394 and modified by the _a_l_i_a_s and _u_n_a_l_i_a_s commands. After a command line is 395 scanned, it is parsed into distinct commands and the first word of each 396 command, left-to-right, is checked to see if it has an alias. If it 397 does, then the text which is the alias for that command is reread with 398 the history mechanism available as though that command were the previous 399 input line. The resulting words replace the command and argument list. 400 If no reference is made to the history list, then the argument list is 401 left unchanged. 402 403 Thus if the alias for `ls' is `ls -l' the command `ls /usr' would map to 404 `ls -l /usr', the argument list here being undisturbed. Similarly if the 405 alias for `lookup' was `grep !^ /etc/passwd' then `lookup bill' would map 406 to `grep bill /etc/passwd'. 407 408 If an alias is found, the word transformation of the input text is 409 performed and the aliasing process begins again on the reformed input 410 line. Looping is prevented if the first word of the new text is the same 411 as the old by flagging it to prevent further aliasing. Other loops are 412 detected and cause an error. 413 414 Note that the mechanism allows aliases to introduce parser metasyntax. 415 Thus we can `alias print 'pr \!* | lpr'' to make a command which _p_r '_s 416 its arguments to the line printer. 417 418 VVaarriiaabbllee ssuubbssttiittuuttiioonn 419 The shell maintains a set of variables, each of which has as value a list 420 of zero or more words. Some of these variables are set by the shell or 421 referred to by it. For instance, the _a_r_g_v variable is an image of the 422 shell's argument list, and words of this variable's value are referred to 423 in special ways. 424 425 The values of variables may be displayed and changed by using the _s_e_t and 426 _u_n_s_e_t commands. Of the variables referred to by the shell a number are 427 toggles; the shell does not care what their value is, only whether they 428 are set or not. For instance, the _v_e_r_b_o_s_e variable is a toggle which 429 causes command input to be echoed. The setting of this variable results 430 from the --vv command line option. 431 432 Other operations treat variables numerically. The `@' command permits 433 numeric calculations to be performed and the result assigned to a 434 variable. Variable values are, however, always represented as (zero or 435 more) strings. For the purposes of numeric operations, the null string 436 is considered to be zero, and the second and subsequent words of 437 multiword values are ignored. 438 439 After the input line is aliased and parsed, and before each command is 440 executed, variable substitution is performed keyed by `$' characters. 441 This expansion can be prevented by preceding the `$' with a `\' except 442 within `"'s where it _a_l_w_a_y_s occurs, and within `''s where it _n_e_v_e_r 443 occurs. Strings quoted by ``' are interpreted later (see CCoommmmaanndd 444 ssuubbssttiittuuttiioonn below) so `$' substitution does not occur there until later, 445 if at all. A `$' is passed unchanged if followed by a blank, tab, or 446 end-of-line. 447 448 Input/output redirections are recognized before variable expansion, and 449 are variable expanded separately. Otherwise, the command name and entire 450 argument list are expanded together. It is thus possible for the first 451 (command) word to this point to generate more than one word, the first of 452 which becomes the command name, and the rest of which become arguments. 453 454 Unless enclosed in `"' or given the `:q' modifier the results of variable 455 substitution may eventually be command and filename substituted. Within 456 `"', a variable whose value consists of multiple words expands to a 457 (portion of) a single word, with the words of the variables value 458 separated by blanks. When the `:q' modifier is applied to a substitution 459 the variable will expand to multiple words with each word separated by a 460 blank and quoted to prevent later command or filename substitution. 461 462 463 The following metasequences are provided for introducing variable values 464 into the shell input. Except as noted, it is an error to reference a 465 variable which is not set. 466 467 $name 468 ${name} 469 Are replaced by the words of the value of variable _n_a_m_e, 470 each separated by a blank. Braces insulate _n_a_m_e from 471 following characters which would otherwise be part of it. 472 Shell variables have names consisting of up to 20 letters 473 and digits starting with a letter. The underscore 474 character is considered a letter. 475 If _n_a_m_e is not a shell variable, but is set in the 476 environment, then that value is returned (but : modifiers 477 and the other forms given below are not available in this 478 case). 479 $name[selector] 480 ${name[selector}] 481 May be used to select only some of the words from the value 482 of _n_a_m_e. The selector is subjected to `$' substitution and 483 may consist of a single number or two numbers separated by 484 a `-'. The first word of a variables value is numbered 485 `1'. If the first number of a range is omitted it defaults 486 to `1'. If the last member of a range is omitted it 487 defaults to `$#name'. The selector `*' selects all words. 488 It is not an error for a range to be empty if the second 489 argument is omitted or in range. 490 $#name 491 ${#name} 492 Gives the number of words in the variable. This is useful 493 for later use in a `$argv[selector]'. 494 $0 Substitutes the name of the file from which command input 495 is being read. An error occurs if the name is not known. 496 $number 497 ${number} 498 Equivalent to `$argv[number]'. 499 $* Equivalent to `$argv[*]'. The modifiers `:e', `:h', `:t', 500 `:r', `:q' and `:x' may be applied to the substitutions 501 above as may `:gh', `:gt' and `:gr'. If braces `{' '}' 502 appear in the command form then the modifiers must appear 503 within the braces. The current implementation allows only 504 one `:' modifier on each `$' expansion. 505 506 The following substitutions may not be modified with `:' modifiers. 507 $?name 508 ${?name} 509 Substitutes the string `1' if name is set, `0' if it is 510 not. 511 $?0 Substitutes `1' if the current input filename is known, `0' 512 if it is not. 513 Substitute the (decimal) process number of the (parent) 514 shell. 515 $< Substitutes a line from the standard input, with no further 516 interpretation thereafter. It can be used to read from the 517 keyboard in a shell script. 518 519 CCoommmmaanndd aanndd ffiilleennaammee ssuubbssttiittuuttiioonn 520 The remaining substitutions, command and filename substitution, are 521 applied selectively to the arguments of builtin commands. This means 522 that portions of expressions which are not evaluated are not subjected to 523 these expansions. For commands which are not internal to the shell, the 524 command name is substituted separately from the argument list. This 525 occurs very late, after input-output redirection is performed, and in a 526 child of the main shell. 527 528 529 CCoommmmaanndd ssuubbssttiittuuttiioonn 530 Command substitution is indicated by a command enclosed in ``'. The 531 output from such a command is normally broken into separate words at 532 blanks, tabs and newlines, with null words being discarded, this text 533 then replacing the original string. Within `"'s, only newlines force new 534 words; blanks and tabs are preserved. 535 536 In any case, the single final newline does not force a new word. Note 537 that it is thus possible for a command substitution to yield only part of 538 a word, even if the command outputs a complete line. 539 540 FFiilleennaammee ssuubbssttiittuuttiioonn 541 If a word contains any of the characters `*', `?', `[' or `{' or begins 542 with the character `~', then that word is a candidate for filename 543 substitution, also known as `globbing'. This word is then regarded as a 544 pattern, and replaced with an alphabetically sorted list of file names 545 which match the pattern. In a list of words specifying filename 546 substitution it is an error for no pattern to match an existing file 547 name, but it is not required for each pattern to match. Only the 548 metacharacters `*', `?' and `[' imply pattern matching, the characters 549 `~' and `{' being more akin to abbreviations. 550 551 In matching filenames, the character `.' at the beginning of a filename 552 or immediately following a `/', as well as the character `/' must be 553 matched explicitly. The character `*' matches any string of characters, 554 including the null string. The character `?' matches any single 555 character. The sequence `[...]' matches any one of the characters 556 enclosed. Within `[...]', a pair of characters separated by `-' matches 557 any character lexically between the two. 558 559 The character `~' at the beginning of a filename is used to refer to home 560 directories. Standing alone, i.e. `~' it expands to the invokers home 561 directory as reflected in the value of the variable _h_o_m_e. When followed 562 by a name consisting of letters, digits and `-' characters the shell 563 searches for a user with that name and substitutes their home directory; 564 thus `~ken' might expand to `/usr/ken' and `~ken/chmach' to 565 `/usr/ken/chmach'. If the character `~' is followed by a character other 566 than a letter or `/' or appears not at the beginning of a word, it is 567 left undisturbed. 568 569 The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'. Left to 570 right order is preserved, with results of matches being sorted separately 571 at a low level to preserve this order. This construct may be nested. 572 Thus `~source/s1/{oldls,ls}.c' expands to `/usr/source/s1/oldls.c 573 /usr/source/s1/ls.c' whether or not these files exist without any chance 574 of error if the home directory for `source' is `/usr/source'. Similarly 575 `../{memo,*box}' might expand to `../memo ../box ../mbox'. (Note that 576 `memo' was not sorted with the results of matching `*box'.) As a special 577 case `{', `}' and `{}' are passed undisturbed. 578 579 IInnppuutt//oouuttppuutt 580 The standard input and standard output of a command may be redirected 581 with the following syntax: 582 583 < name Open file _n_a_m_e (which is first variable, command and 584 filename expanded) as the standard input. 585 << word 586 Read the shell input up to a line which is identical to 587 _w_o_r_d. _W_o_r_d is not subjected to variable, filename or 588 command substitution, and each input line is compared to 589 _w_o_r_d before any substitutions are done on this input line. 590 Unless a quoting `\', `"', `' or ``' appears in _w_o_r_d 591 variable and command substitution is performed on the 592 intervening lines, allowing `\' to quote `$', `\' and ``'. 593 Commands which are substituted have all blanks, tabs, and 594 newlines preserved, except for the final newline which is 595 dropped. The resultant text is placed in an anonymous 596 temporary file which is given to the command as standard 597 input. 598 > name 599 >! name 600 >& name 601 >&! name 602 The file _n_a_m_e is used as standard output. If the file does 603 not exist then it is created; if the file exists, its is 604 truncated, its previous contents being lost. 605 606 If the variable _n_o_c_l_o_b_b_e_r is set, then the file must not 607 exist or be a character special file (e.g. a terminal or 608 `/dev/null') or an error results. This helps prevent 609 accidental destruction of files. In this case the `!' 610 forms can be used and suppress this check. 611 612 The forms involving `&' route the diagnostic output into 613 the specified file as well as the standard output. _N_a_m_e is 614 expanded in the same way as `<' input filenames are. 615 >> name 616 >>& name 617 >>! name 618 >>&! name 619 Uses file _n_a_m_e as standard output like `>' but places 620 output at the end of the file. If the variable _n_o_c_l_o_b_b_e_r 621 is set, then it is an error for the file not to exist 622 unless one of the `!' forms is given. Otherwise similar to 623 `>'. 624 625 A command receives the environment in which the shell was invoked as 626 modified by the input-output parameters and the presence of the command 627 in a pipeline. Thus, unlike some previous shells, commands run from a 628 file of shell commands have no access to the text of the commands by 629 default; rather they receive the original standard input of the shell. 630 The `<<' mechanism should be used to present inline data. This permits 631 shell command scripts to function as components of pipelines and allows 632 the shell to block read its input. Note that the default standard input 633 for a command run detached is _n_o_t modified to be the empty file 634 /_d_e_v/_n_u_l_l; rather the standard input remains as the original standard 635 input of the shell. If this is a terminal and if the process attempts to 636 read from the terminal, then the process will block and the user will be 637 notified (see _J_o_b_s above). 638 639 Diagnostic output may be directed through a pipe with the standard 640 output. Simply use the form `|&' rather than just `|'. 641 642 EExxpprreessssiioonnss 643 A number of the builtin commands (to be described subsequently) take 644 expressions, in which the operators are similar to those of C, with the 645 same precedence. These expressions appear in the @@,, _e_x_i_t, _i_f, and _w_h_i_l_e 646 commands. The following operators are available: 647 648 || && | ^ & == != =~ !~ <= >= < > << >> + - * / % 649 ! ~ ( ) 650 651 Here the precedence increases to the right, `==' `!=' `=~' and `!~', `<=' 652 `>=' `<' and `>', `<<' and `>>', `+' and `-', `*' `/' and `%' being, in 653 groups, at the same level. The `==' `!=' `=~' and `!~' operators compare 654 their arguments as strings; all others operate on numbers. The operators 655 `=~' and `!~' are like `!=' and `==' except that the right hand side is a 656 _p_a_t_t_e_r_n (containing, e.g. `*'s, `?'s and instances of `[...]' against 657 which the left hand operand is matched. This reduces the need for use of 658 the _s_w_i_t_c_h statement in shell scripts when all that is really needed is 659 pattern matching. 660 661 Strings which begin with `0' are considered octal numbers. Null or 662 missing arguments are considered `0'. The result of all expressions are 663 strings, which represent decimal numbers. It is important to note that 664 no two components of an expression can appear in the same word; except 665 when adjacent to components of expressions which are syntactically 666 significant to the parser (`&' `|' `<' `>' `(' `)') they should be 667 surrounded by spaces. 668 669 Also available in expressions as primitive operands are command 670 executions enclosed in `{' and `}' and file enquiries of the form --ll _n_a_m_e 671 where ll is one of: 672 673 r read access 674 w write access 675 x execute access 676 e existence 677 o ownership 678 z zero size 679 f plain file 680 d directory 681 682 The specified name is command and filename expanded and then tested to 683 see if it has the specified relationship to the real user. If the file 684 does not exist or is inaccessible then all enquiries return false, i.e. 685 `0'. Command executions succeed, returning true, i.e. `1', if the 686 command exits with status 0, otherwise they fail, returning false, i.e. 687 `0'. If more detailed status information is required then the command 688 should be executed outside of an expression and the variable _s_t_a_t_u_s 689 examined. 690 691 CCoonnttrrooll ffllooww 692 The shell contains a number of commands which can be used to regulate the 693 flow of control in command files (shell scripts) and (in limited but 694 useful ways) from terminal input. These commands all operate by forcing 695 the shell to reread or skip in its input and, due to the implementation, 696 restrict the placement of some of the commands. 697 698 The ffoorreeaacchh, sswwiittcchh, and wwhhiillee statements, as well as the iiff--tthheenn--eellssee 699 form of the iiff statement require that the major keywords appear in a 700 single simple command on an input line as shown below. 701 702 If the shell's input is not seekable, the shell buffers up input whenever 703 a loop is being read and performs seeks in this internal buffer to 704 accomplish the rereading implied by the loop. (To the extent that this 705 allows, backward goto's will succeed on non-seekable inputs.) 706 707 BBuuiillttiinn ccoommmmaannddss 708 Builtin commands are executed within the shell. If a builtin command 709 occurs as any component of a pipeline except the last then it is executed 710 in a subshell. 711 712 aalliiaass 713 aalliiaass _n_a_m_e 714 aalliiaass _n_a_m_e _w_o_r_d_l_i_s_t 715 The first form prints all aliases. The second form prints 716 the alias for name. The final form assigns the specified 717 _w_o_r_d_l_i_s_t as the alias of _n_a_m_e; _w_o_r_d_l_i_s_t is command and 718 filename substituted. _N_a_m_e is not allowed to be _a_l_i_a_s or 719 _u_n_a_l_i_a_s. 720 721 aalllloocc Shows the amount of dynamic memory acquired, broken down 722 into used and free memory. With an argument shows the 723 number of free and used blocks in each size category. The 724 categories start at size 8 and double at each step. This 725 command's output may vary across system types, since 726 systems other than the VAX may use a different memory 727 allocator. 728 729 bbgg 730 bbgg %%_j_o_b ... 731 Puts the current or specified jobs into the background, 732 continuing them if they were stopped. 733 734 bbrreeaakk Causes execution to resume after the eenndd of the nearest 735 enclosing ffoorreeaacchh or wwhhiillee. The remaining commands on the 736 current line are executed. Multi-level breaks are thus 737 possible by writing them all on one line. 738 739 bbrreeaakkssww 740 Causes a break from a sswwiittcchh, resuming after the eennddssww. 741 742 ccaassee _l_a_b_e_l: 743 A label in a sswwiittcchh statement as discussed below. 744 745 ccdd 746 ccdd _n_a_m_e 747 cchhddiirr 748 cchhddiirr _n_a_m_e 749 Change the shell's working directory to directory _n_a_m_e. If 750 no argument is given then change to the home directory of 751 the user. If _n_a_m_e is not found as a subdirectory of the 752 current directory (and does not begin with `/', `./' or 753 `../'), then each component of the variable ccddppaatthh is 754 checked to see if it has a subdirectory _n_a_m_e. Finally, if 755 all else fails but _n_a_m_e is a shell variable whose value 756 begins with `/', then this is tried to see if it is a 757 directory. 758 759 ccoonnttiinnuuee 760 Continue execution of the nearest enclosing wwhhiillee or 761 ffoorreeaacchh. The rest of the commands on the current line are 762 executed. 763 764 ddeeffaauulltt: 765 Labels the default case in a sswwiittcchh statement. The default 766 should come after all ccaassee labels. 767 768 ddiirrss Prints the directory stack; the top of the stack is at the 769 left, the first directory in the stack being the current 770 directory. 771 772 eecchhoo _w_o_r_d_l_i_s_t 773 eecchhoo --nn _w_o_r_d_l_i_s_t 774 The specified words are written to the shells standard 775 output, separated by spaces, and terminated with a newline 776 unless the --nn option is specified. 777 778 eellssee 779 eenndd 780 eennddiiff 781 eennddssww See the description of the ffoorreeaacchh, iiff, sswwiittcchh, and wwhhiillee 782 statements below. 783 784 eevvaall _a_r_g ... 785 (As in sh(1).) The arguments are read as input to the 786 shell and the resulting command(s) executed in the context 787 of the current shell. This is usually used to execute 788 commands generated as the result of command or variable 789 substitution, since parsing occurs before these 790 substitutions. See tset(1) for an example of using eevvaall. 791 792 793 eexxeecc _c_o_m_m_a_n_d 794 The specified command is executed in place of the current 795 shell. 796 797 eexxiitt 798 eexxiitt (_e_x_p_r) 799 The shell exits either with the value of the ssttaattuuss 800 variable (first form) or with the value of the specified 801 eexxpprr (second form). 802 803 ffgg 804 ffgg %% _j_o_b ... 805 Brings the current or specified jobs into the foreground, 806 continuing them if they were stopped. 807 808 ffoorreeaacchh _n_a_m_e (_w_o_r_d_l_i_s_t) 809 ... 810 eenndd The variable nnaammee is successively set to each member of 811 wwoorrddlliisstt and the sequence of commands between this command 812 and the matching eenndd are executed. (Both ffoorreeaacchh and eenndd 813 must appear alone on separate lines.) The builtin command 814 ccoonnttiinnuuee may be used to continue the loop prematurely and 815 the builtin command bbrreeaakk to terminate it prematurely. 816 When this command is read from the terminal, the loop is 817 read up once prompting with `?' before any statements in 818 the loop are executed. If you make a mistake typing in a 819 loop at the terminal you can rub it out. 820 821 gglloobb _w_o_r_d_l_i_s_t 822 Like eecchhoo but no `\' escapes are recognized and words are 823 delimited by null characters in the output. Useful for 824 programs which wish to use the shell to filename expand a 825 list of words. 826 827 ggoottoo _w_o_r_d 828 The specified wwoorrdd is filename and command expanded to 829 yield a string of the form `label'. The shell rewinds its 830 input as much as possible and searches for a line of the 831 form `label:' possibly preceded by blanks or tabs. 832 Execution continues after the specified line. 833 834 hhaasshhssttaatt 835 Print a statistics line indicating how effective the 836 internal hash table has been at locating commands (and 837 avoiding eexxeecc's). An eexxeecc is attempted for each component 838 of the _p_a_t_h where the hash function indicates a possible 839 hit, and in each component which does not begin with a `/'. 840 841 hhiissttoorryy 842 hhiissttoorryy _n 843 hhiissttoorryy --rr _n 844 hhiissttoorryy --hh _n 845 Displays the history event list; if _n is given only the _n 846 most recent events are printed. The --rr option reverses the 847 order of printout to be most recent first rather than 848 oldest first. The --hh option causes the history list to be 849 printed without leading numbers. This is used to produce 850 files suitable for sourceing using the -h option to ssoouurrccee. 851 852 iiff (_e_x_p_r command) 853 If the specified expression evaluates true, then the single 854 _c_o_m_m_a_n_d with arguments is executed. Variable substitution 855 on _c_o_m_m_a_n_d happens early, at the same time it does for the 856 rest of the iiff command. _C_o_m_m_a_n_d must be a simple command, 857 not a pipeline, a command list, or a parenthesized command 858 list. Input/output redirection occurs even if _e_x_p_r is 859 false, when command is nnoott executed (this is a bug). 860 861 iiff (_e_x_p_r) tthheenn 862 ... 863 eellssee iiff (_e_x_p_r_2) tthheenn 864 ... 865 eellssee 866 ... 867 eennddiiff If the specified _e_x_p_r is true then the commands to the 868 first eellssee are executed; otherwise if _e_x_p_r_2 is true then 869 the commands to the second eellssee are executed, etc. Any 870 number of eellssee--iiff pairs are possible; only one eennddiiff is 871 needed. The eellssee part is likewise optional. (The words 872 eellssee and eennddiiff must appear at the beginning of input lines; 873 the iiff must appear alone on its input line or after an 874 eellssee.) 875 876 jjoobbss 877 jjoobbss --ll 878 Lists the active jobs; given the --ll options lists process 879 id's in addition to the normal information. 880 881 kkiillll %% _j_o_b 882 kkiillll _p_i_d 883 kkiillll --ssiigg _p_i_d ... 884 kkiillll --ll 885 Sends either the TERM (terminate) signal or the specified 886 signal to the specified jobs or processes. Signals are 887 either given by number or by names (as given in 888 /_u_s_r/_i_n_c_l_u_d_e/_s_i_g_n_a_l._h, stripped of the prefix ``SIG''). 889 The signal names are listed by ``kill -l''. There is no 890 default, saying just `kill' does not send a signal to the 891 current job. If the signal being sent is TERM (terminate) 892 or HUP (hangup), then the job or process will be sent a 893 CONT (continue) signal as well. 894 895 lliimmiitt 896 lliimmiitt _r_e_s_o_u_r_c_e 897 lliimmiitt _r_e_s_o_u_r_c_e _m_a_x_i_m_u_m-_u_s_e 898 lliimmiitt --hh 899 lliimmiitt --hh _r_e_s_o_u_r_c_e 900 lliimmiitt --hh _r_e_s_o_u_r_c_e _m_a_x_i_m_u_m-_u_s_e 901 Limits the consumption by the current process and each 902 process it creates to not individually exceed _m_a_x_i_m_u_m-_u_s_e 903 on the specified _r_e_s_o_u_r_c_e. If no _m_a_x_i_m_u_m-_u_s_e is given, then 904 the current limit is printed; if no _r_e_s_o_u_r_c_e is given, then 905 all limitations are given. If the --hh flag is given, the 906 hard limits are used instead of the current limits. The 907 hard limits impose a ceiling on the values of the current 908 limits. Only the super-user may raise the hard limits, but 909 a user may lower or raise the current limits within the 910 legal range. 911 912 Resources controllable currently include _c_p_u_t_i_m_e (the 913 maximum number of cpu-seconds to be used by each process), 914 _f_i_l_e_s_i_z_e (the largest single file which can be created), 915 _d_a_t_a_s_i_z_e (the maximum growth of the data+stack region via 916 sbrk(2) beyond the end of the program text), _s_t_a_c_k_s_i_z_e (the 917 maximum size of the automatically-extended stack region), 918 and _c_o_r_e_d_u_m_p_s_i_z_e (the size of the largest core dump that 919 will be created). 920 921 The _m_a_x_i_m_u_m-_u_s_e may be given as a (floating point or 922 integer) number followed by a scale factor. For all limits 923 other than _c_p_u_t_i_m_e the default scale is `k' or `kilobytes' 924 (1024 bytes); a scale factor of `m' or `megabytes' may also 925 be used. For _c_p_u_t_i_m_e the default scaling is `seconds', 926 while `m' for minutes or `h' for hours, or a time of the 927 form `mm:ss' giving minutes and seconds may be used. 928 929 For both _r_e_s_o_u_r_c_e names and scale factors, unambiguous 930 prefixes of the names suffice. 931 932 llooggiinn Terminate a login shell, replacing it with an instance of 933 /_b_i_n/_l_o_g_i_n. This is one way to log off, included for 934 compatibility with sh(1). 935 936 llooggoouutt Terminate a login shell. Especially useful if iiggnnoorreeeeooff is 937 set. 938 939 nniiccee 940 nniiccee +_n_u_m_b_e_r 941 nniiccee _c_o_m_m_a_n_d 942 nniiccee +_n_u_m_b_e_r _c_o_m_m_a_n_d 943 The first form sets the scheduling priority for this shell 944 to 4. The second form sets the priority to the given 945 _n_u_m_b_e_r. The final two forms run command at priority 4 and 946 _n_u_m_b_e_r respectively. The greater the number, the less cpu 947 the process will get. The super-user may specify negative 948 priority by using `nice -number ...'. Command is always 949 executed in a sub-shell, and the restrictions placed on 950 commands in simple iiff statements apply. 951 952 nnoohhuupp 953 nnoohhuupp _c_o_m_m_a_n_d 954 The first form can be used in shell scripts to cause 955 hangups to be ignored for the remainder of the script. The 956 second form causes the specified command to be run with 957 hangups ignored. All processes detached with `&' are 958 effectively nnoohhuupp'ed. 959 960 nnoottiiffyy 961 nnoottiiffyy %% _j_o_b ... 962 Causes the shell to notify the user asynchronously when the 963 status of the current or specified jobs changes; normally 964 notification is presented before a prompt. This is 965 automatic if the shell variable nnoottiiffyy is set. 966 967 oonniinnttrr 968 oonniinnttrr -- 969 oonniinnttrr _l_a_b_e_l 970 Control the action of the shell on interrupts. The first 971 form restores the default action of the shell on interrupts 972 which is to terminate shell scripts or to return to the 973 terminal command input level. The second form `onintr -' 974 causes all interrupts to be ignored. The final form causes 975 the shell to execute a `goto label' when an interrupt is 976 received or a child process terminates because it was 977 interrupted. 978 979 In any case, if the shell is running detached and 980 interrupts are being ignored, all forms of oonniinnttrr have no 981 meaning and interrupts continue to be ignored by the shell 982 and all invoked commands. 983 984 ppooppdd 985 ppooppdd +_n 986 Pops the directory stack, returning to the new top 987 directory. With an argument `+ _n' discards the _n'th entry 988 in the stack. The elements of the directory stack are 989 numbered from 0 starting at the top. 990 991 ppuusshhdd 992 ppuusshhdd _n_a_m_e 993 ppuusshhdd _n 994 With no arguments, ppuusshhdd exchanges the top two elements of 995 the directory stack. Given a _n_a_m_e argument, ppuusshhdd changes 996 to the new directory (ala ccdd) and pushes the old current 997 working directory (as in ccssww) onto the directory stack. 998 With a numeric argument, rotates the _n'th argument of the 999 directory stack around to be the top element and changes to 1000 it. The members of the directory stack are numbered from 1001 the top starting at 0. 1002 1003 rreehhaasshh Causes the internal hash table of the contents of the 1004 directories in the ppaatthh variable to be recomputed. This is 1005 needed if new commands are added to directories in the ppaatthh 1006 while you are logged in. This should only be necessary if 1007 you add commands to one of your own directories, or if a 1008 systems programmer changes the contents of one of the 1009 system directories. 1010 1011 rreeppeeaatt _c_o_u_n_t _c_o_m_m_a_n_d 1012 The specified _c_o_m_m_a_n_d which is subject to the same 1013 restrictions as the _c_o_m_m_a_n_d in the one line iiff statement 1014 above, is executed _c_o_u_n_t times. I/O redirections occur 1015 exactly once, even if _c_o_u_n_t is 0. 1016 1017 sseett 1018 sseett _n_a_m_e 1019 sseett _n_a_m_e=word 1020 sseett _n_a_m_e[_i_n_d_e_x]=word 1021 sseett _n_a_m_e=(wordlist) 1022 The first form of the command shows the value of all shell 1023 variables. Variables which have other than a single word 1024 as value print as a parenthesized word list. The second 1025 form sets nnaammee to the null string. The third form sets 1026 nnaammee to the single wwoorrdd. The fourth form sets the _i_n_d_e_x'th 1027 component of name to word; this component must already 1028 exist. The final form sets _n_a_m_e to the list of words in 1029 _w_o_r_d_l_i_s_t. In all cases the value is command and filename 1030 expanded. 1031 1032 These arguments may be repeated to set multiple values in a 1033 single set command. Note however, that variable expansion 1034 happens for all arguments before any setting occurs. 1035 1036 sseetteennvv 1037 sseetteennvv _n_a_m_e _v_a_l_u_e 1038 sseetteennvv _n_a_m_e 1039 The first form lists all current environment variables. 1040 The last form sets the value of environment variable _n_a_m_e 1041 to be _v_a_l_u_e, a single string. The second form sets _n_a_m_e to 1042 an empty string. The most commonly used environment 1043 variable USER, TERM, and PATH are automatically imported to 1044 and exported from the ccsshh variables _u_s_e_r, [_t_e_r_m], and _p_a_t_h; 1045 there is no need to use sseetteennvv for these. 1046 1047 sshhiifftt 1048 sshhiifftt _v_a_r_i_a_b_l_e 1049 The members of aarrggvv are shifted to the left, discarding 1050 aarrggvv [1]. It is an error for aarrggvv not to be set or to have 1051 less than one word as value. The second form performs the 1052 same function on the specified variable. 1053 1054 1055 1056 ssoouurrccee _n_a_m_e 1057 ssoouurrccee --hh _n_a_m_e 1058 The shell reads commands from nnaammee. SSoouurrccee commands may be 1059 nested; if they are nested too deeply the shell may run out 1060 of file descriptors. An error in a ssoouurrccee at any level 1061 terminates all nested ssoouurrccee commands. Normally input 1062 during ssoouurrccee commands is not placed on the history list; 1063 the -h option causes the commands to be placed in the 1064 history list without being executed. 1065 1066 ssttoopp 1067 ssttoopp %%_j_o_b ... 1068 Stops the current or specified job which is executing in 1069 the background. 1070 1071 ssuussppeenndd 1072 Causes the shell to stop in its tracks, much as if it had 1073 been sent a stop signal with ^^ZZ. This is most often used to 1074 stop shells started by su(1). 1075 1076 sswwiittcchh (_s_t_r_i_n_g) 1077 ccaassee _s_t_r_1: 1078 ... 1079 bbrreeaakkssww 1080 ... 1081 ddeeffaauulltt: 1082 ... 1083 bbrreeaakkssww 1084 eennddssww Each case label is successively matched, against the 1085 specified _s_t_r_i_n_g which is first command and filename 1086 expanded. The file metacharacters `*', `?' and `[...]' 1087 may be used in the case labels, which are variable 1088 expanded. If none of the labels match before a `default' 1089 label is found, then the execution begins after the default 1090 label. Each case label and the default label must appear 1091 at the beginning of a line. The command bbrreeaakkssww causes 1092 execution to continue after the eennddssww. Otherwise control 1093 may fall through case labels and default labels as in C. 1094 If no label matches and there is no default, execution 1095 continues after the eennddssww. 1096 1097 ttiimmee 1098 ttiimmee _c_o_m_m_a_n_d 1099 With no argument, a summary of time used by this shell and 1100 its children is printed. If arguments are given the 1101 specified simple command is timed and a time summary as 1102 described under the ttiimmee variable is printed. If 1103 necessary, an extra shell is created to print the time 1104 statistic when the command completes. 1105 1106 uummaasskk 1107 uummaasskk _v_a_l_u_e 1108 The file creation mask is displayed (first form) or set to 1109 the specified value (second form). The mask is given in 1110 octal. Common values for the mask are 002 giving all 1111 access to the group and read and execute access to others 1112 or 022 giving all access except no write access for users 1113 in the group or others. 1114 1115 uunnaalliiaass _p_a_t_t_e_r_n 1116 All aliases whose names match the specified pattern are 1117 discarded. Thus all aliases are removed by `unalias *'. 1118 It is not an error for nothing to be uunnaalliiaasseedd. 1119 1120 1121 1122 uunnhhaasshh Use of the internal hash table to speed location of 1123 executed programs is disabled. 1124 1125 uunnlliimmiitt 1126 uunnlliimmiitt _r_e_s_o_u_r_c_e 1127 uunnlliimmiitt --hh 1128 uunnlliimmiitt --hh _r_e_s_o_u_r_c_e 1129 Removes the limitation on _r_e_s_o_u_r_c_e. If no _r_e_s_o_u_r_c_e is 1130 specified, then all _r_e_s_o_u_r_c_e limitations are removed. If 1131 --hh is given, the corresponding hard limits are removed. 1132 Only the super-user may do this. 1133 1134 uunnsseett _p_a_t_t_e_r_n 1135 All variables whose names match the specified pattern are 1136 removed. Thus all variables are removed by `unset *'; this 1137 has noticeably distasteful side-effects. It is not an 1138 error for nothing to be uunnsseett. 1139 1140 uunnsseetteennvv _p_a_t_t_e_r_n 1141 Removes all variables whose name match the specified 1142 pattern from the environment. See also the sseetteennvv command 1143 above and printenv(1). 1144 1145 wwaaiitt All background jobs are waited for. It the shell is 1146 interactive, then an interrupt can disrupt the wait, at 1147 which time the shell prints names and job numbers of all 1148 jobs known to be outstanding. 1149 1150 wwhhiillee (_e_x_p_r) 1151 ... 1152 eenndd While the specified expression evaluates non-zero, the 1153 commands between the wwhhiillee and the matching end are 1154 evaluated. BBrreeaakk and ccoonnttiinnuuee may be used to terminate or 1155 continue the loop prematurely. (The wwhhiillee and eenndd must 1156 appear alone on their input lines.) Prompting occurs here 1157 the first time through the loop as for the ffoorreeaacchh 1158 statement if the input is a terminal. 1159 1160 %% _j_o_b Brings the specified job into the foreground. 1161 1162 %% _j_o_b && 1163 Continues the specified job in the background. 1164 1165 @@ 1166 @@_n_a_m_e= expr 1167 @@_n_a_m_e[_i_n_d_e_x]= expr 1168 The first form prints the values of all the shell 1169 variables. The second form sets the specified _n_a_m_e to the 1170 value of _e_x_p_r. If the expression contains `<', `>', `&' or 1171 `' then at least this part of the expression must be placed 1172 within `(' `)'. The third form assigns the value of _e_x_p_r 1173 to the _i_n_d_e_x'th argument of _n_a_m_e. Both _n_a_m_e and its 1174 _i_n_d_e_x'th component must already exist. 1175 1176 The operators `*=', `+=', etc are available as in C. The space 1177 separating the name from the assignment operator is optional. Spaces 1178 are, however, mandatory in separating components of _e_x_p_r which would 1179 otherwise be single words. 1180 1181 Special postfix `++' and `--' operators increment and decrement _n_a_m_e 1182 respectively, i.e. `@ i++'. 1183 1184 PPrree--ddeeffiinneedd aanndd eennvviirroonnmmeenntt vvaarriiaabblleess 1185 The following variables have special meaning to the shell. Of these, 1186 _a_r_g_v, _c_w_d, _h_o_m_e, _p_a_t_h, _p_r_o_m_p_t, _s_h_e_l_l and _s_t_a_t_u_s are always set by the 1187 shell. Except for _c_w_d and _s_t_a_t_u_s this setting occurs only at 1188 initialization; these variables will not then be modified unless this is 1189 done explicitly by the user. 1190 1191 This shell copies the environment variable USER into the variable _u_s_e_r, 1192 TERM into _t_e_r_m, and HOME into _h_o_m_e, and copies these back into the 1193 environment whenever the normal shell variables are reset. The 1194 environment variable PATH is likewise handled; it is not necessary to 1195 worry about its setting other than in the file ._c_s_h_r_c as inferior ccsshh 1196 processes will import the definition of _p_a_t_h from the environment, and 1197 re-export it if you then change it. 1198 1199 aarrggvv Set to the arguments to the shell, it is from this variable 1200 that positional parameters are substituted, i.e. `$1' is 1201 replaced by `$argv[1]', etc. 1202 1203 ccddppaatthh Gives a list of alternate directories searched to find 1204 subdirectories in _c_h_d_i_r commands. 1205 1206 ccwwdd The full pathname of the current directory. 1207 1208 eecchhoo Set when the --xx command line option is given. Causes each 1209 command and its arguments to be echoed just before it is 1210 executed. For non-builtin commands all expansions occur 1211 before echoing. Builtin commands are echoed before command 1212 and filename substitution, since these substitutions are then 1213 done selectively. 1214 1215 ffiilleecc Enable file name completion. 1216 1217 hhiissttcchhaarrss Can be given a string value to change the characters used in 1218 history substitution. The first character of its value is 1219 used as the history substitution character, replacing the 1220 default character `!'. The second character of its value 1221 replaces the character `^' in quick substitutions. 1222 1223 hhiissttoorryy Can be given a numeric value to control the size of the 1224 history list. Any command which has been referenced in this 1225 many events will not be discarded. Too large values of 1226 _h_i_s_t_o_r_y may run the shell out of memory. The last executed 1227 command is always saved on the history list. 1228 1229 hhoommee The home directory of the invoker, initialized from the 1230 environment. The filename expansion of `~' refers to this 1231 variable. 1232 1233 iiggnnoorreeeeooff If set the shell ignores end-of-file from input devices which 1234 are terminals. This prevents shells from accidentally being 1235 killed by control-D's. 1236 1237 mmaaiill The files where the shell checks for mail. This is done after 1238 each command completion which will result in a prompt, if a 1239 specified interval has elapsed. The shell says `You have new 1240 mail.' if the file exists with an access time not greater 1241 than its modify time. 1242 1243 If the first word of the value of _m_a_i_l is numeric it specifies 1244 a different mail checking interval, in seconds, than the 1245 default, which is 10 minutes. 1246 1247 If multiple mail files are specified, then the shell says `New 1248 mail in _n_a_m_e' when there is mail in the file _n_a_m_e. 1249 1250 nnoocclloobbbbeerr As described in the section on _I_n_p_u_t/_o_u_t_p_u_t, restrictions are 1251 placed on output redirection to insure that files are not 1252 accidentally destroyed, and that `>>' redirections refer to 1253 1254 existing files. 1255 1256 nnoogglloobb If set, filename expansion is inhibited. This is most useful 1257 in shell scripts which are not dealing with filenames, or 1258 after a list of filenames has been obtained and further 1259 expansions are not desirable. 1260 1261 nnoonnoommaattcchh If set, it is not an error for a filename expansion to not 1262 match any existing files; rather the primitive pattern is 1263 returned. It is still an error for the primitive pattern to 1264 be malformed, i.e. `echo [' still gives an error. 1265 1266 nnoottiiffyy If set, the shell notifies asynchronously of job completions. 1267 The default is to rather present job completions just before 1268 printing a prompt. 1269 1270 ppaatthh Each word of the path variable specifies a directory in which 1271 commands are to be sought for execution. A null word 1272 specifies the current directory. If there is no _p_a_t_h variable 1273 then only full path names will execute. The usual search path 1274 is `.', `/bin' and `/usr/bin', but this may vary from system 1275 to system. For the super-user the default search path is 1276 `/etc', `/bin' and `/usr/bin'. A shell which is given neither 1277 the --cc nor the --tt option will normally hash the contents of 1278 the directories in the _p_a_t_h variable after reading ._c_s_h_r_c, and 1279 each time the _p_a_t_h variable is reset. If new commands are 1280 added to these directories while the shell is active, it may 1281 be necessary to do a rreehhaasshh or the commands may not be found. 1282 1283 pprroommpptt The string which is printed before each command is read from 1284 an interactive terminal input. If a `!' appears in the string 1285 it will be replaced by the current event number unless a 1286 preceding `\' is given. Default is `% ', or `# ' for the 1287 super-user. 1288 1289 ssaavveehhiisstt Is given a numeric value to control the number of entries of 1290 the history list that are saved in ~/.history when the user 1291 logs out. Any command which has been referenced in this many 1292 events will be saved. During start up the shell sources 1293 ~/.history into the history list enabling history to be saved 1294 across logins. Too large values of _s_a_v_e_h_i_s_t will slow down 1295 the shell during start up. 1296 1297 sshheellll The file in which the shell resides. This is used in forking 1298 shells to interpret files which have execute bits set, but 1299 which are not executable by the system. (See the description 1300 of _N_o_n-_b_u_i_l_t_i_n _C_o_m_m_a_n_d _E_x_e_c_u_t_i_o_n below.) Initialized to the 1301 (system-dependent) home of the shell. 1302 1303 ssttaattuuss The status returned by the last command. If it terminated 1304 abnormally, then 0200 is added to the status. Builtin 1305 commands which fail return exit status `1', all other builtin 1306 commands set status `0'. 1307 1308 ttiimmee Controls automatic timing of commands. If set, then any 1309 command which takes more than this many cpu seconds will cause 1310 a line giving user, system, and real times and a utilization 1311 percentage which is the ratio of user plus system times to 1312 real time to be printed when it terminates. 1313 1314 vveerrbboossee Set by the --vv command line option, causes the words of each 1315 command to be printed after history substitution. 1316 1317 NNoonn--bbuuiillttiinn ccoommmmaanndd eexxeeccuuttiioonn 1318 When a command to be executed is found to not be a builtin command the 1319 shell attempts to execute the command via execve(2). Each word in the 1320 variable _p_a_t_h names a directory from which the shell will attempt to 1321 execute the command. If it is given neither a --cc nor a --tt option, the 1322 shell will hash the names in these directories into an internal table so 1323 that it will only try an eexxeecc in a directory if there is a possibility 1324 that the command resides there. This greatly speeds command location 1325 when a large number of directories are present in the search path. If 1326 this mechanism has been turned off (via uunnhhaasshh), or if the shell was 1327 given a --cc or --tt argument, and in any case for each directory component 1328 of _p_a_t_h which does not begin with a `/', the shell concatenates with the 1329 given command name to form a path name of a file which it then attempts 1330 to execute. 1331 1332 Parenthesized commands are always executed in a subshell. Thus 1333 1334 (cd; pwd); pwd 1335 1336 prints the _h_o_m_e directory; leaving you where you were (printing this 1337 after the home directory), while 1338 1339 cd; pwd 1340 1341 leaves you in the _h_o_m_e directory. Parenthesized commands are most often 1342 used to prevent cchhddiirr from affecting the current shell. 1343 1344 If the file has execute permissions but is not an executable binary to 1345 the system, then it is assumed to be a file containing shell commands and 1346 a new shell is spawned to read it. 1347 1348 If there is an aalliiaass for sshheellll then the words of the alias will be 1349 prepended to the argument list to form the shell command. The first word 1350 of the aalliiaass should be the full path name of the shell (e.g. `$shell'). 1351 Note that this is a special, late occurring, case of aalliiaass substitution, 1352 and only allows words to be prepended to the argument list without 1353 modification. 1354 1355 SSiiggnnaall hhaannddlliinngg 1356 The shell normally ignores _q_u_i_t signals. Jobs running detached (either 1357 by && or the bbgg or %%...... && commands) are immune to signals generated from 1358 the keyboard, including hangups. Other signals have the values which the 1359 shell inherited from its parent. The shell's handling of interrupts and 1360 terminate signals in shell scripts can be controlled by oonniinnttrr. Login 1361 shells catch the _t_e_r_m_i_n_a_t_e signal; otherwise this signal is passed on to 1362 children from the state in the shell's parent. In no case are interrupts 1363 allowed when a login shell is reading the file ._l_o_g_o_u_t. 1364 1365AAUUTTHHOORR 1366 William Joy. Job control and directory stack features first implemented 1367 by J.E. Kulp of IIASA, Laxenburg, Austria, with different syntax than 1368 that used now. File name completion code written by Ken Greer, HP Labs. 1369 Eight-bit implementation Christos S. Zoulas, Cornell University. 1370 1371FFIILLEESS 1372 ~/.cshrc Read at beginning of execution by each shell. 1373 ~/.login Read by login shell, after `.cshrc' at login. 1374 ~/.logout Read by login shell, at logout. 1375 /bin/sh Standard shell, for shell scripts not starting with a `#'. 1376 /tmp/sh* Temporary file for `<<'. 1377 /etc/passwd Source of home directories for `~name'. 1378 1379LLIIMMIITTAATTIIOONNSS 1380 Word lengths - Words can be no longer than 1024 characters. The system 1381 limits argument lists to 10240 characters. The number of arguments to a 1382 command which involves filename expansion is limited to 1/6'th the number 1383 of characters allowed in an argument list. Command substitutions may 1384 substitute no more characters than are allowed in an argument list. To 1385 detect looping, the shell restricts the number of aalliiaass substitutions on 1386 a single line to 20. 1387 1388SSEEEE AALLSSOO 1389 sh(1), access(2), execve(2), fork(2), killpg(2), pipe(2), 1390 sigvec(2), umask(2), setrlimit(2), wait(2), tty(4), a.out(5), 1391 environ(7), 1392 introduction to the C shell 1393 1394HHIISSTTOORRYY 1395 CCsshh appeared in 3BSD. It was a first implementation of a command language 1396 interpreter incorporating a history mechanism (see _H_i_s_t_o_r_y 1397 _S_u_b_s_t_i_t_u_t_i_o_n_s), job control facilities (see _J_o_b_s), interactive file name 1398 and user name completion (see _F_i_l_e _N_a_m_e _C_o_m_p_l_e_t_i_o_n), and a C-like syntax. 1399 There are now many shells which also have these mechanisms, plus a few 1400 more (and maybe some bugs too), which are available thru the usenet, or 1401 with BSD UNIX as contributed software like the ksh(korn shell). 1402 1403BBUUGGSS 1404 When a command is restarted from a stop, the shell prints the directory 1405 it started in if this is different from the current directory; this can 1406 be misleading (i.e. wrong) as the job may have changed directories 1407 internally. 1408 1409 Shell builtin functions are not stoppable/restartable. Command sequences 1410 of the form `a ; b ; c' are also not handled gracefully when stopping is 1411 attempted. If you suspend `b', the shell will then immediately execute 1412 `c'. This is especially noticeable if this expansion results from an 1413 _a_l_i_a_s. It suffices to place the sequence of commands in ()'s to force it 1414 to a subshell, i.e. `( a ; b ; c )'. 1415 1416 Control over tty output after processes are started is primitive; perhaps 1417 this will inspire someone to work on a good virtual terminal interface. 1418 In a virtual terminal interface much more interesting things could be 1419 done with output control. 1420 1421 Alias substitution is most often used to clumsily simulate shell 1422 procedures; shell procedures should be provided rather than aliases. 1423 1424 Commands within loops, prompted for by `?', are not placed in the hhiissttoorryy 1425 list. Control structure should be parsed rather than being recognized as 1426 built-in commands. This would allow control commands to be placed 1427 anywhere, to be combined with `|', and to be used with `&' and `;' 1428 metasyntax. 1429 1430 It should be possible to use the `:' modifiers on the output of command 1431 substitutions. All and more than one `:' modifier should be allowed on 1432 `$' substitutions. 1433 1434 The way the ffiilleecc facility is implemented is ugly and expensive. 1435 14364th Berkeley Distribution June 7, 1991 22 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453