1.\" Copyright (c) 1980, 1990, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)csh.1 8.4 (Berkeley) 06/01/94 7.\" 8.Dd 9.Dt CSH 1 10.Os BSD 4 11.Sh NAME 12.Nm csh 13.Nd a shell (command interpreter) with C-like syntax 14.Sh SYNOPSIS 15.Nm csh 16.Op Fl bcefinstvVxX 17.Op arg ... 18.Nm csh 19.Op Fl l 20.Sh DESCRIPTION 21The 22.Nm csh 23is a command language interpreter 24incorporating a history mechanism (see 25.Nm History Substitutions ) , 26job control facilities (see 27.Nm Jobs ) , 28interactive file name 29and user name completion (see 30.Nm File Name Completion ) , 31and a C-like syntax. It is used both as an interactive 32login shell and a shell script command processor. 33.Ss Argument list processing 34If the first argument (argument 0) to the shell is 35.Ql Fl \& , 36then this is a login shell. 37A login shell also can be specified by invoking the shell with the 38.Ql Fl l 39flag as the only argument. 40.Pp 41The rest of the flag arguments are interpreted as follows: 42.Bl -tag -width 5n 43.It Fl b 44This flag forces a ``break'' from option processing, causing any further 45shell arguments to be treated as non-option arguments. 46The remaining arguments will not be interpreted as shell options. 47This may be used to pass options to a shell script without confusion 48or possible subterfuge. 49The shell will not run a set-user ID script without this option. 50.It Fl c 51Commands are read from the (single) following argument which must 52be present. 53Any remaining arguments are placed in 54.Ar argv . 55.It Fl e 56The shell exits if any invoked command terminates abnormally 57or yields a non-zero exit status. 58.It Fl f 59The shell will start faster, because it will neither search for nor 60execute commands from the file 61.Pa \&.cshrc 62in the invoker's home directory. 63.It Fl i 64The shell is interactive and prompts for its top-level input, 65even if it appears not to be a terminal. 66Shells are interactive without this option if their inputs 67and outputs are terminals. 68.It Fl l 69The shell is a login shell (only applicable if 70.Fl l 71is the only flag specified). 72.It Fl n 73Commands are parsed, but not executed. 74This aids in syntactic checking of shell scripts. 75.It Fl s 76Command input is taken from the standard input. 77.It Fl t 78A single line of input is read and executed. 79A 80.Ql \e 81may be used to escape the newline at the end of this 82line and continue onto another line. 83.It Fl v 84Causes the 85.Ar verbose 86variable to be set, with the effect 87that command input is echoed after history substitution. 88.It Fl x 89Causes the 90.Ar echo 91variable to be set, so that commands are echoed immediately before execution. 92.It Fl V 93Causes the 94.Ar verbose 95variable to be set even before 96.Pa .cshrc 97is executed. 98.It Fl X 99Is to 100.Fl x 101as 102.Fl V 103is to 104.Fl v . 105.El 106.Pp 107After processing of flag arguments, if arguments remain but none of the 108.Fl c , 109.Fl i , 110.Fl s , 111or 112.Fl t 113options were given, the first argument is taken as the name of a file of 114commands to be executed. 115The shell opens this file, and saves its name for possible resubstitution 116by `$0'. 117Since many systems use either the standard version 6 or version 7 shells 118whose shell scripts are not compatible with this shell, the shell will 119execute such a `standard' shell if the first character of a script 120is not a `#', i.e., if the script does not start with a comment. 121Remaining arguments initialize the variable 122.Ar argv . 123.Pp 124An instance of 125.Nm csh 126begins by executing commands from the file 127.Pa /etc/csh.cshrc 128and, 129if this is a login shell, 130.Pa \&/etc/csh.login . 131It then executes 132commands from 133.Pa \&.cshrc 134in the 135.Ar home 136directory of the invoker, and, if this is a login shell, the file 137.Pa \&.login 138in the same location. 139It is typical for users on crt's to put the command ``stty crt'' 140in their 141.Pa \&.login 142file, and to also invoke 143.Xr tset 1 144there. 145.Pp 146In the normal case, the shell will begin reading commands from the 147terminal, prompting with `% '. 148Processing of arguments and the use of the shell to process files 149containing command scripts will be described later. 150.Pp 151The shell repeatedly performs the following actions: 152a line of command input is read and broken into 153.Ar words . 154This sequence of words is placed on the command history list and parsed. 155Finally each command in the current line is executed. 156.Pp 157When a login shell terminates it executes commands from the files 158.Pa .logout 159in the user's 160.Ar home 161directory and 162.Pa /etc/csh.logout . 163.Ss Lexical structure 164The shell splits input lines into words at blanks and tabs with the 165following exceptions. 166The characters 167`&' `\&|' `;' `<' `>' `(' `)' 168form separate words. 169If doubled in `&&', `\&|\&|', `<<' or `>>' these pairs form single words. 170These parser metacharacters may be made part of other words, or prevented their 171special meaning, by preceding them with `\e'. 172A newline preceded by a `\e' is equivalent to a blank. 173.Pp 174Strings enclosed in matched pairs of quotations, 175`'\|', `\*(ga' or `"', 176form parts of a word; metacharacters in these strings, including blanks 177and tabs, do not form separate words. 178These quotations have semantics to be described later. 179Within pairs of `\'' or `"' characters, a newline preceded by a `\e' gives 180a true newline character. 181.Pp 182When the shell's input is not a terminal, 183the character `#' introduces a comment that continues to the end of the 184input line. 185It is prevented this special meaning when preceded by `\e' 186and in quotations using `\`', `\'', and `"'. 187.Ss Commands 188A simple command is a sequence of words, the first of which 189specifies the command to be executed. 190A simple command or 191a sequence of simple commands separated by `\&|' characters 192forms a pipeline. 193The output of each command in a pipeline is connected to the input of the next. 194Sequences of pipelines may be separated by `;', and are then executed 195sequentially. 196A sequence of pipelines may be executed without immediately 197waiting for it to terminate by following it with an `&'. 198.Pp 199Any of the above may be placed in `(' `)' to form a simple command (that 200may be a component of a pipeline, etc.). 201It is also possible to separate pipelines with `\&|\&|' or `&&' showing, 202as in the C language, 203that the second is to be executed only if the first fails or succeeds 204respectively. (See 205.Em Expressions . ) 206.Ss Jobs 207The shell associates a 208.Ar job 209with each pipeline. It keeps 210a table of current jobs, printed by the 211.Ar jobs 212command, and assigns them small integer numbers. When 213a job is started asynchronously with `&', the shell prints a line that looks 214like: 215.Bd -filled -offset indent 216.Op 1 2171234 218.Ed 219.Pp 220showing that the job which was started asynchronously was job number 2211 and had one (top-level) process, whose process id was 1234. 222.Pp 223If you are running a job and wish to do something else you may hit the key 224.Nm ^Z 225(control-Z) which sends a STOP signal to the current job. 226The shell will then normally show that the job has been `Stopped', 227and print another prompt. You can then manipulate the state of this job, 228putting it in the 229.Em background 230with the 231.Ar bg 232command, or run some other 233commands and eventually bring the job back into the foreground with 234the 235.Em foreground 236command 237.Ar fg . 238A 239.Nm ^Z 240takes effect immediately and 241is like an interrupt in that pending output and unread input are discarded 242when it is typed. There is another special key 243.Nm ^Y 244that does not generate a STOP signal until a program attempts to 245.Xr read 2 246it. 247This request can usefully be typed ahead when you have prepared some commands 248for a job that you wish to stop after it has read them. 249.Pp 250A job being run in the background will stop if it tries to read 251from the terminal. Background jobs are normally allowed to produce output, 252but this can be disabled by giving the command ``stty tostop''. 253If you set this 254tty option, then background jobs will stop when they try to produce 255output like they do when they try to read input. 256.Pp 257There are several ways to refer to jobs in the shell. The character 258`%' introduces a job name. If you wish to refer to job number 1, you can 259name it as `%1'. Just naming a job brings it to the foreground; thus 260`%1' is a synonym for `fg %1', bringing job number 1 back into the foreground. 261Similarly saying `%1 &' resumes job number 1 in the background. 262Jobs can also be named by prefixes of the string typed in to start them, 263if these prefixes are unambiguous, thus `%ex' would normally restart 264a suspended 265.Xr ex 1 266job, if there were only one suspended job whose name began with 267the string `ex'. It is also possible to say `%?string' 268which specifies a job whose text contains 269.Ar string , 270if there is only one such job. 271.Pp 272The shell maintains a notion of the current and previous jobs. 273In output about jobs, the current job is marked with a `+' 274and the previous job with a `\-'. The abbreviation `%+' refers 275to the current job and `%\-' refers to the previous job. For close 276analogy with the syntax of the 277.Ar history 278mechanism (described below), 279`%%' is also a synonym for the current job. 280.Pp 281The job control mechanism requires that the 282.Xr stty 1 283option 284.Ic new 285be set. It is an artifact from a 286.Em new 287implementation 288of the 289tty driver that allows generation of interrupt characters from 290the keyboard to tell jobs to stop. See stty(1) for details 291on setting options in the new tty driver. 292.Ss Status reporting 293This shell learns immediately whenever a process changes state. 294It normally informs you whenever a job becomes blocked so that 295no further progress is possible, but only just before it prints 296a prompt. This is done so that it does not otherwise disturb your work. 297If, however, you set the shell variable 298.Ar notify , 299the shell will notify you immediately of changes of status in background 300jobs. 301There is also a shell command 302.Ar notify 303that marks a single process so that its status changes will be immediately 304reported. By default 305.Ar notify 306marks the current process; 307simply say `notify' after starting a background job to mark it. 308.Pp 309When you try to leave the shell while jobs are stopped, you will 310be warned that `You have stopped jobs.' You may use the 311.Ar jobs 312command to see what they are. If you do this or immediately try to 313exit again, the shell will not warn you a second time, and the suspended 314jobs will be terminated. 315.Ss File Name Completion 316When the file name completion feature is enabled by setting 317the shell variable 318.Ar filec 319(see 320.Ic set ) , 321.Nm csh 322will 323interactively complete file names and user names from unique 324prefixes, when they are input from the terminal followed by 325the escape character (the escape key, or control-[) 326For example, 327if the current directory looks like 328.Bd -literal -offset indent 329DSC.OLD bin cmd lib xmpl.c 330DSC.NEW chaosnet cmtest mail xmpl.o 331bench class dev mbox xmpl.out 332.Ed 333.Pp 334and the input is 335.Pp 336.Dl % vi ch<escape> 337.ne 1i 338.Pp 339.Nm csh 340will complete the prefix ``ch'' 341to the only matching file name ``chaosnet'', changing the input 342line to 343.Pp 344.Dl % vi chaosnet 345.Pp 346However, given 347.Pp 348.Dl % vi D<escape> 349.Pp 350.Nm csh 351will only expand the input to 352.Pp 353.Dl % vi DSC. 354.Pp 355and will sound the terminal bell to indicate that the expansion is 356incomplete, since there are two file names matching the prefix ``D''. 357.Pp 358If a partial file name is followed by the end-of-file character 359(usually control-D), then, instead of completing the name, 360.Nm csh 361will list all file names matching the prefix. For example, 362the input 363.Pp 364.Dl % vi D<control-D> 365.Pp 366causes all files beginning with ``D'' to be listed: 367.Pp 368.Dl DSC.NEW DSC.OLD 369.Pp 370while the input line remains unchanged. 371.Pp 372The same system of escape and end-of-file can also be used to 373expand partial user names, if the word to be completed 374(or listed) begins with the character ``~''. For example, 375typing 376.Pp 377.Dl cd ~ro<escape> 378.Pp 379may produce the expansion 380.Pp 381.Dl cd ~root 382.Pp 383The use of the terminal bell to signal errors or multiple matches 384can be inhibited by setting the variable 385.Ar nobeep . 386.Pp 387Normally, all files in the particular directory are candidates 388for name completion. Files with certain suffixes can be excluded 389from consideration by setting the variable 390.Ar fignore 391to the 392list of suffixes to be ignored. Thus, if 393.Ar fignore 394is set by 395the command 396.Pp 397.Dl % set fignore = (.o .out) 398.Pp 399then typing 400.Pp 401.Dl % vi x<escape> 402.Pp 403would result in the completion to 404.Pp 405.Dl % vi xmpl.c 406.Pp 407ignoring the files "xmpl.o" and "xmpl.out". 408However, if the only completion possible requires not ignoring these 409suffixes, then they are not ignored. In addition, 410.Ar fignore 411does not affect the listing of file names by control-D. All files 412are listed regardless of their suffixes. 413.Ss Substitutions 414We now describe the various transformations the shell performs on the 415input in the order in which they occur. 416.Ss History substitutions 417History substitutions place words from previous command input as portions 418of new commands, making it easy to repeat commands, repeat arguments 419of a previous command in the current command, or fix spelling mistakes 420in the previous command with little typing and a high degree of confidence. 421History substitutions begin with the character `!' and may begin 422.Ar anywhere 423in the input stream (with the proviso that they 424.Nm "do not" 425nest.) 426This `!' may be preceded by a `\e' to prevent its special meaning; for 427convenience, an `!' is passed unchanged when it is followed by a blank, 428tab, newline, `=' or `('. 429(History substitutions also occur when an input line begins with `\*(ua'. 430This special abbreviation will be described later.) 431Any input line that contains history substitution is echoed on the terminal 432before it is executed as it could have been typed without history substitution. 433.Pp 434Commands input from the terminal that consist of one or more words 435are saved on the history list. 436The history substitutions reintroduce sequences of words from these 437saved commands into the input stream. 438The size of the history list is controlled by the 439.Ar history 440variable; the previous command is always retained, 441regardless of the value of the history variable. 442Commands are numbered sequentially from 1. 443.Pp 444For definiteness, consider the following output from the 445.Ar history 446command: 447.Bd -literal -offset indent 448\09 write michael 44910 ex write.c 45011 cat oldwrite.c 45112 diff *write.c 452.Ed 453.Pp 454The commands are shown with their event numbers. 455It is not usually necessary to use event numbers, but the current event 456number can be made part of the 457.Ar prompt 458by placing an `!' in the prompt string. 459.Pp 460With the current event 13 we can refer to previous events by event 461number `!11', relatively as in `!\-2' (referring to the same event), 462by a prefix of a command word 463as in `!d' for event 12 or `!wri' for event 9, or by a string contained in 464a word in the command as in `!?mic?' also referring to event 9. 465These forms, without further change, simply reintroduce the words 466of the specified events, each separated by a single blank. 467As a special case, `!!' refers to the previous command; thus `!!' 468alone is a 469.Ar redo . 470.Pp 471To select words from an event we can follow the event specification by 472a `:' and a designator for the desired words. 473The words of an input line are numbered from 0, 474the first (usually command) word being 0, the second word (first argument) 475being 1, etc. 476The basic word designators are: 477.Pp 478.Bl -tag -width Ds -compact -offset indent 479.It \&0 480first (command) word 481.It Ar n 482.Ar n Ns 'th 483argument 484.It \*(ua 485first argument, i.e., `1' 486.It $ 487last argument 488.It % 489word matched by (immediately preceding) 490.No \&? Ns Ar s Ns \&? 491search 492.It Ar \&x\-y 493range of words 494.It Ar \&\-y 495abbreviates 496.Ar `\&0\-y\' 497.It * 498abbreviates `\*(ua\-$', or nothing if only 1 word in event 499.It Ar x* 500abbreviates 501.Ar `x\-$\' 502.It Ar x\- 503like 504.Ar `x*\' 505but omitting word `$' 506.El 507.Pp 508The `:' separating the event specification from the word designator 509can be omitted if the argument selector begins with a `\*(ua', `$', `*' 510`\-' or `%'. 511After the optional word designator can be 512placed a sequence of modifiers, each preceded by a `:'. 513The following modifiers are defined: 514.Pp 515.Bl -tag -width Ds -compact -offset indent 516.It h 517Remove a trailing pathname component, leaving the head. 518.It r 519Remove a trailing `.xxx' component, leaving the root name. 520.It e 521Remove all but the extension `.xxx' part. 522.It s Ns Ar /l/r/ 523Substitute 524.Ar l 525for 526.Ar r 527.It t 528Remove all leading pathname components, leaving the tail. 529.It \&& 530Repeat the previous substitution. 531.It g 532Apply the change once on each word, prefixing the above, e.g., `g&'. 533.It a 534Apply the change as many times as possible on a single word, prefixing 535the above. It can be used together with `g' to apply a substitution 536globally. 537.It p 538Print the new command line but do not execute it. 539.It q 540Quote the substituted words, preventing further substitutions. 541.It x 542Like q, but break into words at blanks, tabs and newlines. 543.El 544.Pp 545Unless preceded by a `g' the change is applied only to the first 546modifiable word. With substitutions, it is an error for no word to be 547applicable. 548.Pp 549The left hand side of substitutions are not regular expressions in the sense 550of the editors, but instead strings. 551Any character may be used as the delimiter in place of `/'; 552a `\e' quotes the delimiter into the 553.Ar l " " 554and 555.Ar r " " 556strings. 557The character `&' in the right hand side is replaced by the text from 558the left. 559A `\e' also quotes `&'. 560A null 561.Ar l 562(`//') 563uses the previous string either from an 564.Ar l 565or from a 566contextual scan string 567.Ar s 568in 569.No \&`!? Ns Ar s Ns \e?' . 570The trailing delimiter in the substitution may be omitted if a newline 571follows immediately as may the trailing `?' in a contextual scan. 572.Pp 573A history reference may be given without an event specification, e.g., `!$'. 574Here, the reference is to the previous command unless a previous 575history reference occurred on the same line in which case this form repeats 576the previous reference. 577Thus `!?foo?\*(ua !$' gives the first and last arguments 578from the command matching `?foo?'. 579.Pp 580A special abbreviation of a history reference occurs when the first 581non-blank character of an input line is a `\*(ua'. 582This is equivalent to `!:s\*(ua' providing a convenient shorthand for substitutions 583on the text of the previous line. 584Thus `\*(ualb\*(ualib' fixes the spelling of 585`lib' 586in the previous command. 587Finally, a history substitution may be surrounded with `{' and `}' 588if necessary to insulate it from the characters that follow. 589Thus, after `ls \-ld ~paul' we might do `!{l}a' to do `ls \-ld ~paula', 590while `!la' would look for a command starting with `la'. 591.Pp 592.Ss Quotations with \' and \&" 593The quotation of strings by `\'' and `"' can be used 594to prevent all or some of the remaining substitutions. 595Strings enclosed in `\'' are prevented any further interpretation. 596Strings enclosed in `"' may be expanded as described below. 597.Pp 598In both cases the resulting text becomes (all or part of) a single word; 599only in one special case (see 600.Em Command Substitution 601below) does a `"' quoted string yield parts of more than one word; 602`\'' quoted strings never do. 603.Ss Alias substitution 604The shell maintains a list of aliases that can be established, displayed 605and modified by the 606.Ar alias 607and 608.Ar unalias 609commands. 610After a command line is scanned, it is parsed into distinct commands and 611the first word of each command, left-to-right, is checked to see if it 612has an alias. 613If it does, then the text that is the alias for that command is reread 614with the history mechanism available 615as though that command were the previous input line. 616The resulting words replace the 617command and argument list. 618If no reference is made to the history list, then the argument list is 619left unchanged. 620.Pp 621Thus if the alias for `ls' is `ls \-l' the command `ls /usr' would map to 622`ls \-l /usr', the argument list here being undisturbed. 623Similarly if the alias for `lookup' was `grep !\*(ua /etc/passwd' then 624`lookup bill' would map to `grep bill /etc/passwd'. 625.Pp 626If an alias is found, the word transformation of the input text 627is performed and the aliasing process begins again on the reformed input line. 628Looping is prevented if the first word of the new text is the same as the old 629by flagging it to prevent further aliasing. 630Other loops are detected and cause an error. 631.Pp 632Note that the mechanism allows aliases to introduce parser metasyntax. 633Thus, we can `alias print \'pr \e!* \&| lpr\'' to make a command that 634.Ar pr Ns 's 635its arguments to the line printer. 636.Ss Variable substitution 637The shell maintains a set of variables, each of which has as value a list 638of zero or more words. 639Some of these variables are set by the shell or referred to by it. 640For instance, the 641.Ar argv 642variable is an image of the shell's argument list, and words of this 643variable's value are referred to in special ways. 644.Pp 645The values of variables may be displayed and changed by using the 646.Ar set 647and 648.Ar unset 649commands. 650Of the variables referred to by the shell a number are toggles; 651the shell does not care what their value is, 652only whether they are set or not. 653For instance, the 654.Ar verbose 655variable is a toggle that causes command input to be echoed. 656The setting of this variable results from the 657.Fl v 658command line option. 659.Pp 660Other operations treat variables numerically. 661The `@' command permits numeric calculations to be performed and the result 662assigned to a variable. 663Variable values are, however, always represented as (zero or more) strings. 664For the purposes of numeric operations, the null string is considered to be 665zero, and the second and additional words of multiword values are ignored. 666.Pp 667After the input line is aliased and parsed, and before each command 668is executed, variable substitution 669is performed keyed by `$' characters. 670This expansion can be prevented by preceding the `$' with a `\e' except 671within `"'s where it 672.Em always 673occurs, and within `\''s where it 674.Em never 675occurs. 676Strings quoted by `\*(ga' are interpreted later (see 677.Nm "Command substitution" 678below) so `$' substitution does not occur there until later, if at all. 679A `$' is passed unchanged if followed by a blank, tab, or end-of-line. 680.Pp 681Input/output redirections are recognized before variable expansion, 682and are variable expanded separately. 683Otherwise, the command name and entire argument list are expanded together. 684It is thus possible for the first (command) word (to this point) to generate 685more than one word, the first of which becomes the command name, 686and the rest of which become arguments. 687.Pp 688Unless enclosed in `"' or given the `:q' modifier the results of variable 689substitution may eventually be command and filename substituted. 690Within `"', a variable whose value consists of multiple words expands to a 691(portion of) a single word, with the words of the variables value 692separated by blanks. 693When the `:q' modifier is applied to a substitution 694the variable will expand to multiple words with each word separated 695by a blank and quoted to prevent later command or filename substitution. 696.Pp 697The following metasequences are provided for introducing variable values into 698the shell input. 699Except as noted, it is an error to reference a variable that is not set. 700.Pp 701.Bl -tag -width Ds -compact -offset indent 702.It $name 703.It ${name} 704Are replaced by the words of the value of variable 705.Ar name , 706each separated by a blank. 707Braces insulate 708.Ar name 709from following characters that would otherwise be part of it. 710Shell variables have names consisting of up to 20 letters and digits 711starting with a letter. The underscore character is considered a letter. 712If 713.Ar name 714is not a shell variable, but is set in the environment, then 715that value is returned (but 716.Nm : 717modifiers and the other forms 718given below are not available here). 719.It $name Ns Op selector 720.It ${name Ns [ selector ] } 721May be used to select only some of the words from the value of 722.Ar name . 723The selector is subjected to `$' substitution and may consist of a single 724number or two numbers separated by a `\-'. 725The first word of a variables value is numbered `1'. 726If the first number of a range is omitted it defaults to `1'. 727If the last number of a range is omitted it defaults to `$#name'. 728The selector `*' selects all words. 729It is not an error for a range to be empty if the second argument is omitted 730or in range. 731.ne 1i 732.It $#name 733.It ${#name} 734Gives the number of words in the variable. 735This is useful for later use in a 736`$argv[selector]'. 737.It $0 738Substitutes the name of the file from which command input is being read. 739An error occurs if the name is not known. 740.It $number 741.It ${number} 742Equivalent to 743`$argv[number]'. 744.It $* 745Equivalent to 746`$argv[*]'. 747The modifiers `:e', `:h', `:t', `:r', `:q' and `:x' may be applied to 748the substitutions above as may `:gh', `:gt' and `:gr'. 749If braces `{' '}' appear in the command form then the modifiers 750must appear within the braces. 751The current implementation allows only one `:' modifier on each `$' expansion. 752.El 753.Pp 754The following substitutions may not be modified with `:' modifiers. 755.Bl -tag -width Ds -compact -offset indent 756.It $?name 757.It ${?name} 758Substitutes the string `1' if name is set, `0' if it is not. 759.It $?0 760Substitutes `1' if the current input filename is known, `0' if it is not. 761.It \&$\&$\& 762Substitute the (decimal) process number of the (parent) shell. 763.It $! 764Substitute the (decimal) process number of the last background process 765started by this shell. 766.It $< 767Substitutes a line from the standard 768input, with no further interpretation. 769It can be used to read from the keyboard in a shell script. 770.El 771.Ss Command and filename substitution 772The remaining substitutions, command and filename substitution, 773are applied selectively to the arguments of builtin commands. 774By selectively, we mean that portions of expressions which are 775not evaluated are not subjected to these expansions. 776For commands that are not internal to the shell, the command 777name is substituted separately from the argument list. 778This occurs very late, 779after input-output redirection is performed, and in a child 780of the main shell. 781.Ss Command substitution 782Command substitution is shown by a command enclosed in `\*(ga'. 783The output from such a command is normally broken into separate words 784at blanks, tabs and newlines, with null words being discarded; 785this text then replaces the original string. 786Within `"'s, only newlines force new words; blanks and tabs are preserved. 787.Pp 788In any case, the single final newline does not force a new word. 789Note that it is thus possible for a command substitution to yield 790only part of a word, even if the command outputs a complete line. 791.Ss Filename substitution 792If a word contains any of the characters `*', `?', `[' or `{' 793or begins with the character `~', then that word is a candidate for 794filename substitution, also known as `globbing'. 795This word is then regarded as a pattern, and replaced with an alphabetically 796sorted list of file names that match the pattern. 797In a list of words specifying filename substitution it is an error for 798no pattern to match an existing file name, but it is not required 799for each pattern to match. 800Only the metacharacters `*', `?' and `[' imply pattern matching, 801the characters `~' and `{' being more akin to abbreviations. 802.Pp 803In matching filenames, the character `.' at the beginning of a filename 804or immediately following a `/', as well as the character `/' must 805be matched explicitly. 806The character `*' matches any string of characters, including the null 807string. 808The character `?' matches any single character. 809The sequence 810.Sq Op ... 811matches any one of the characters enclosed. 812Within 813.Sq Op ... , 814a pair of characters separated by `\-' matches any character lexically between 815the two (inclusive). 816.Pp 817The character `~' at the beginning of a filename refers to home 818directories. 819Standing alone, i.e., `~' it expands to the invokers home directory as reflected 820in the value of the variable 821.Ar home . 822When followed by a name consisting of letters, digits and `\-' characters, 823the shell searches for a user with that name and substitutes their 824home directory; thus `~ken' might expand to `/usr/ken' and `~ken/chmach' 825to `/usr/ken/chmach'. 826If the character `~' is followed by a character other than a letter or `/' 827or does not appear at the beginning of a word, 828it is left undisturbed. 829.Pp 830The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'. 831Left to right order is preserved, with results of matches being sorted 832separately at a low level to preserve this order. 833This construct may be nested. 834Thus, `~source/s1/{oldls,ls}.c' expands to 835`/usr/source/s1/oldls.c /usr/source/s1/ls.c' 836without chance of error 837if the home directory for `source' is `/usr/source'. 838Similarly `../{memo,*box}' might expand to `../memo ../box ../mbox'. 839(Note that `memo' was not sorted with the results of the match to `*box'.) 840As a special case `{', `}' and `{}' are passed undisturbed. 841.Ss Input/output 842The standard input and the standard output of a command may be redirected 843with the following syntax: 844.Pp 845.Bl -tag -width Ds -compact -offset indent 846.It < name 847Open file 848.Ar name 849(which is first variable, command and filename expanded) as the standard 850input. 851.It << word 852Read the shell input up to a line that is identical to 853.Ar word . 854.Ar Word 855is not subjected to variable, filename or command substitution, 856and each input line is compared to 857.Ar word 858before any substitutions are done on the input line. 859Unless a quoting `\e', `"', `\*(aa' or `\*(ga' appears in 860.Ar word , 861variable and command substitution is performed on the intervening lines, 862allowing `\e' to quote `$', `\e' and `\*(ga'. 863Commands that are substituted have all blanks, tabs, and newlines 864preserved, except for the final newline which is dropped. 865The resultant text is placed in an anonymous temporary file that 866is given to the command as its standard input. 867.It > name 868.It >! name 869.It >& name 870.It >&! name 871The file 872.Ar name 873is used as the standard output. 874If the file does not exist then it is created; 875if the file exists, it is truncated; its previous contents are lost. 876.Pp 877If the variable 878.Ar noclobber 879is set, then the file must not exist or be a character special file (e.g., a 880terminal or `/dev/null') or an error results. 881This helps prevent accidental destruction of files. 882Here, the `!' forms can be used to suppress this check. 883.Pp 884The forms involving `&' route the standard error output into the specified 885file as well as the standard output. 886.Ar Name 887is expanded in the same way as `<' input filenames are. 888.It >> name 889.It >>& name 890.It >>! name 891.It >>&! name 892Uses file 893.Ar name 894as the standard output; 895like `>' but places output at the end of the file. 896If the variable 897.Ar noclobber 898is set, then it is an error for the file not to exist unless 899one of the `!' forms is given. 900Otherwise similar to `>'. 901.El 902.Pp 903A command receives the environment in which the shell was 904invoked as modified by the input-output parameters and 905the presence of the command in a pipeline. 906Thus, unlike some previous shells, commands run from a file of shell commands 907have no access to the text of the commands by default; 908instead they receive the original standard input of the shell. 909The `<<' mechanism should be used to present inline data. 910This permits shell command scripts to function as components of pipelines 911and allows the shell to block read its input. 912Note that the default standard input for a command run detached is 913.Ar not 914modified to be the empty file 915.Pa /dev/null ; 916instead the standard input 917remains as the original standard input of the shell. If this is a terminal 918and if the process attempts to read from the terminal, then the process 919will block and the user will be notified (see 920.Sx Jobs 921above). 922.Pp 923The standard error output may be directed through 924a pipe with the standard output. 925Simply use the form `\&|&' instead of just `\&|'. 926.Ss Expressions 927Several of the builtin commands (to be described later) 928take expressions, in which the operators are similar to those of C, with 929the same precedence. 930These expressions appear in the 931.Nm @, 932.Ar exit , 933.Ar if , 934and 935.Ar while 936commands. 937The following operators are available: 938.Bd -ragged -offset indent 939\&|\&| && \&| \*(ua & == != =~ !~ <= >= 940< > << >> + \- * / % ! ~ ( ) 941.Ed 942.Pp 943Here the precedence increases to the right, 944`==' `!=' `=~' and `!~', `<=' `>=' `<' and `>', `<<' and `>>', `+' and `\-', 945`*' `/' and `%' being, in groups, at the same level. 946The `==' `!=' `=~' and `!~' operators compare their arguments as strings; 947all others operate on numbers. 948The operators `=~' and `!~' are like `!=' and `==' except that the right 949hand side is a 950.Ar pattern 951(containing, e.g., `*'s, `?'s and instances of `[...]') 952against which the left hand operand is matched. This reduces the 953need for use of the 954.Ar switch 955statement in shell scripts when all that is really needed is pattern matching. 956.Pp 957Strings that begin with `0' are considered octal numbers. 958Null or missing arguments are considered `0'. 959The result of all expressions are strings, 960which represent decimal numbers. 961It is important to note that no two components of an expression can appear 962in the same word; except when adjacent to components of expressions that 963are syntactically significant to the parser (`&' `\&|' `<' `>' `(' `)'), 964they should be surrounded by spaces. 965.Pp 966Also available in expressions as primitive operands are command executions 967enclosed in `{' and `}' 968and file enquiries of the form 969.Fl l 970.Ar name 971where 972.Ic l 973is one of: 974.Bd -literal -offset indent 975r read access 976w write access 977x execute access 978e existence 979o ownership 980z zero size 981f plain file 982d directory 983.Ed 984.Pp 985The specified name is command and filename expanded and then tested 986to see if it has the specified relationship to the real user. 987If the file does not exist or is inaccessible then all enquiries return 988false, i.e., `0'. 989Command executions succeed, returning true, i.e., `1', 990if the command exits with status 0, otherwise they fail, returning 991false, i.e., `0'. 992If more detailed status information is required then the command 993should be executed outside an expression and the variable 994.Ar status 995examined. 996.Ss Control flow 997The shell contains several commands that can be used to regulate the 998flow of control in command files (shell scripts) and 999(in limited but useful ways) from terminal input. 1000These commands all operate by forcing the shell to reread or skip in its 1001input and, because of the implementation, restrict the placement of some 1002of the commands. 1003.Pp 1004The 1005.Ic foreach , 1006.Ic switch , 1007and 1008.Ic while 1009statements, as well as the 1010.Ic if\-then\-else 1011form of the 1012.Ic if 1013statement require that the major keywords appear in a single simple command 1014on an input line as shown below. 1015.pl +1 1016.Pp 1017If the shell's input is not seekable, 1018the shell buffers up input whenever a loop is being read 1019and performs seeks in this internal buffer to accomplish the rereading 1020implied by the loop. 1021(To the extent that this allows, backward goto's will succeed on 1022non-seekable inputs.) 1023.Ss Builtin commands 1024Builtin commands are executed within the shell. 1025If a builtin command occurs as any component of a pipeline 1026except the last then it is executed in a subshell. 1027.Pp 1028.Bl -tag -width Ds -compact -offset indent 1029.It Ic alias 1030.It Ic alias Ar name 1031.It Ic alias Ar name wordlist 1032The first form prints all aliases. 1033The second form prints the alias for name. 1034The final form assigns the specified 1035.Ar wordlist 1036as the alias of 1037.Ar name ; 1038.Ar wordlist 1039is command and filename substituted. 1040.Ar Name 1041is not allowed to be 1042.Ar alias 1043or 1044.Ar unalias . 1045.Pp 1046.It Ic alloc 1047Shows the amount of dynamic memory acquired, broken down into used and 1048free memory. 1049With an argument shows the number of free and used blocks in each size 1050category. The categories start at size 8 and double at each step. 1051This command's output may vary across system types, since 1052systems other than the VAX may use a different memory allocator. 1053.Pp 1054.It Ic bg 1055.It Ic bg \&% Ns Ar job ... 1056Puts the current or specified jobs into the background, continuing them 1057if they were stopped. 1058.Pp 1059.It Ic break 1060Causes execution to resume after the 1061.Ic end 1062of the nearest enclosing 1063.Ic foreach 1064or 1065.Ic while . 1066The remaining commands on the current line are executed. 1067Multi-level breaks are thus possible by writing them all on one line. 1068.Pp 1069.It Ic breaksw 1070Causes a break from a 1071.Ic switch , 1072resuming after the 1073.Ic endsw . 1074.Pp 1075.It Ic case Ar label : 1076A label in a 1077.Ic switch 1078statement as discussed below. 1079.Pp 1080.It Ic cd 1081.It Ic cd Ar name 1082.It Ic chdir 1083.It Ic chdir Ar name 1084Change the shell's working directory to directory 1085.Ar name . 1086If no argument is given then change to the home directory of the user. 1087If 1088.Ar name 1089is not found as a subdirectory of the current directory (and does not begin 1090with `/', `./' or `../'), then each 1091component of the variable 1092.Ic cdpath 1093is checked to see if it has a subdirectory 1094.Ar name . 1095Finally, if all else fails but 1096.Ar name 1097is a shell variable whose value begins with `/', then this 1098is tried to see if it is a directory. 1099.Pp 1100.It Ic continue 1101Continue execution of the nearest enclosing 1102.Ic while 1103or 1104.Ic foreach . 1105The rest of the commands on the current line are executed. 1106.Pp 1107.It Ic default : 1108Labels the default case in a 1109.Ic switch 1110statement. 1111The default should come after all 1112.Ic case 1113labels. 1114.Pp 1115.It Ic dirs 1116Prints the directory stack; the top of the stack is at the left, 1117the first directory in the stack being the current directory. 1118.Pp 1119.It Ic echo Ar wordlist 1120.It Ic echo Fl n Ar wordlist 1121The specified words are written to the shell's standard output, separated 1122by spaces, and terminated with a newline unless the 1123.Fl n 1124option is specified. 1125.Pp 1126.It Ic else 1127.It Ic end 1128.It Ic endif 1129.It Ic endsw 1130See the description of the 1131.Ic foreach , 1132.Ic if , 1133.Ic switch , 1134and 1135.Ic while 1136statements below. 1137.Pp 1138.It Ic eval Ar arg ... 1139(As in 1140.Xr sh 1 . ) 1141The arguments are read as input to the shell and the resulting 1142command(s) executed in the context of the current shell. 1143This is usually used to execute commands 1144generated as the result of command or variable substitution, since 1145parsing occurs before these substitutions. See 1146.Xr tset 1 1147for an example of using 1148.Ic eval . 1149.Pp 1150.It Ic exec Ar command 1151The specified command is executed in place of the current shell. 1152.Pp 1153.It Ic exit 1154.It Ic exit Ar (expr ) 1155The shell exits either with the value of the 1156.Ic status 1157variable (first form) or with the value of the specified 1158.Ic expr 1159(second form). 1160.Pp 1161.It Ic fg 1162.It Ic fg % Ns Ar job ... 1163Brings the current or specified jobs into the foreground, continuing them if 1164they were stopped. 1165.Pp 1166.It Ic foreach Ar name (wordlist) 1167.It ... 1168.It Ic end 1169The variable 1170.Ic name 1171is successively set to each member of 1172.Ic wordlist 1173and the sequence of commands between this command and the matching 1174.Ic end 1175are executed. 1176(Both 1177.Ic foreach 1178and 1179.Ic end 1180must appear alone on separate lines.) 1181The builtin command 1182.Ic continue 1183may be used to continue the loop prematurely and the builtin 1184command 1185.Ic break 1186to terminate it prematurely. 1187When this command is read from the terminal, the loop is read once 1188prompting with `?' before any statements in the loop are executed. 1189If you make a mistake typing in a loop at the terminal you can rub it out. 1190.Pp 1191.It Ic glob Ar wordlist 1192Like 1193.Ic echo 1194but no `\e' escapes are recognized and words are delimited 1195by null characters in the output. 1196Useful for programs that wish to use the shell to filename expand a list 1197of words. 1198.Pp 1199.It Ic goto Ar word 1200The specified 1201.Ic word 1202is filename and command expanded to yield a string of the form `label'. 1203The shell rewinds its input as much as possible 1204and searches for a line of the form `label:' 1205possibly preceded by blanks or tabs. 1206Execution continues after the specified line. 1207.Pp 1208.It Ic hashstat 1209Print a statistics line showing how effective the internal hash 1210table has been at locating commands (and avoiding 1211.Ic exec Ns \'s ) . 1212An 1213.Ic exec 1214is attempted for each component of the 1215.Em path 1216where the hash function indicates a possible hit, and in each component 1217that does not begin with a `/'. 1218.Pp 1219.It Ic history 1220.It Ic history Ar n 1221.It Ic history Fl r Ar n 1222.It Ic history Fl h Ar n 1223Displays the history event list; if 1224.Ar n 1225is given only the 1226.Ar n 1227most recent events are printed. 1228The 1229.Fl r 1230option reverses the order of printout to be most recent first 1231instead of oldest first. 1232The 1233.Fl h 1234option causes the history list to be printed without leading numbers. 1235This format produces files suitable for sourcing using the \-h 1236option to 1237.Ic source . 1238.Pp 1239.It Ic if ( Ar expr ) No command 1240If the specified expression evaluates true, then the single 1241.Ar command 1242with arguments is executed. 1243Variable substitution on 1244.Ar command 1245happens early, at the same 1246time it does for the rest of the 1247.Ic if 1248command. 1249.Ar Command 1250must be a simple command, not 1251a pipeline, a command list, or a parenthesized command list. 1252Input/output redirection occurs even if 1253.Ar expr 1254is false, i.e., when command is 1255.Sy not 1256executed (this is a bug). 1257.Pp 1258.It Ic if ( Ar expr ) Ic then 1259.It ... 1260.It Ic else if ( Ar expr2 ) Ic then 1261.It ... 1262.It Ic else 1263.It ... 1264.It Ic endif 1265If the specified 1266.Ar expr 1267is true then the commands up to the first 1268.Ic else 1269are executed; otherwise if 1270.Ar expr2 1271is true then the commands up to the 1272second 1273.Ic else 1274are executed, etc. 1275Any number of 1276.Ic else-if 1277pairs are possible; only one 1278.Ic endif 1279is needed. 1280The 1281.Ic else 1282part is likewise optional. 1283(The words 1284.Ic else 1285and 1286.Ic endif 1287must appear at the beginning of input lines; 1288the 1289.Ic if 1290must appear alone on its input line or after an 1291.Ic else . ) 1292.Pp 1293.It Ic jobs 1294.It Ic jobs Fl l 1295Lists the active jobs; the 1296.Fl l 1297option lists process id's in addition to the normal information. 1298.Pp 1299.It Ic kill % Ns Ar job 1300.It Ic kill Ar pid 1301.It Ic kill Fl sig Ar pid ... 1302.It Ic kill Fl l 1303Sends either the TERM (terminate) signal or the 1304specified signal to the specified jobs or processes. 1305Signals are either given by number or by names (as given in 1306.Pa /usr/include/signal.h, 1307stripped of the prefix ``SIG''). 1308The signal names are listed by ``kill \-l''. 1309There is no default, just saying `kill' does not 1310send a signal to the current job. 1311If the signal being sent is TERM (terminate) or HUP (hangup), 1312then the job or process will be sent a CONT (continue) signal as well. 1313.Pp 1314.It Ic limit 1315.It Ic limit Ar resource 1316.It Ic limit Ar resource maximum-use 1317.It Ic limit Fl h 1318.It Ic limit Fl h Ar resource 1319.It Ic limit Fl h Ar resource maximum-use 1320Limits the consumption by the current process and each process 1321it creates to not individually exceed 1322.Ar maximum-use 1323on the 1324specified 1325.Ar resource . 1326If no 1327.Ar maximum-use 1328is given, then 1329the current limit is printed; if no 1330.Ar resource 1331is given, then 1332all limitations are given. If the 1333.Fl h 1334flag is given, the hard limits are used instead of the current 1335limits. The hard limits impose a ceiling on the values of 1336the current limits. Only the super-user may raise the hard limits, 1337but a user may lower or raise the current limits within the legal range. 1338.Pp 1339Resources controllable currently include 1340.Ar cputime 1341(the maximum 1342number of cpu-seconds to be used by each process), 1343.Ar filesize 1344(the largest single file that can be created), 1345.Ar datasize 1346(the maximum growth of the data+stack region via 1347.Xr sbrk 2 1348beyond the end of the program text), 1349.Ar stacksize 1350(the maximum 1351size of the automatically-extended stack region), and 1352.Ar coredumpsize 1353(the size of the largest core dump that will be created). 1354.lp -1 1355.ne 1i 1356.Pp 1357The 1358.Ar maximum-use 1359may be given as a (floating point or integer) 1360number followed by a scale factor. For all limits other than 1361.Ar cputime 1362the default scale is `k' or `kilobytes' (1024 bytes); 1363a scale factor of `m' or `megabytes' may also be used. 1364For 1365.Ar cputime 1366the default scale is `seconds'; 1367a scale factor of `m' for minutes 1368or `h' for hours, or a time of the form `mm:ss' giving minutes 1369and seconds also may be used. 1370.Pp 1371For both 1372.Ar resource 1373names and scale factors, unambiguous prefixes 1374of the names suffice. 1375.Pp 1376.It Ic login 1377Terminate a login shell, replacing it with an instance of 1378.Pa /bin/login. 1379This is one way to log off, included for compatibility with 1380.Xr sh 1 . 1381.Pp 1382.It Ic logout 1383Terminate a login shell. 1384Especially useful if 1385.Ic ignoreeof 1386is set. 1387.Pp 1388.It Ic nice 1389.It Ic nice Ar +number 1390.It Ic nice Ar command 1391.It Ic nice Ar +number command 1392The first form sets the 1393scheduling priority 1394for this shell to 4. 1395The second form sets the 1396priority 1397to the given 1398.Ar number . 1399The final two forms run command at priority 4 and 1400.Ar number 1401respectively. 1402The greater the number, the less cpu the process will get. 1403The super-user may specify negative priority by using `nice \-number ...'. 1404.Ar Command 1405is always executed in a sub-shell, and the restrictions 1406placed on commands in simple 1407.Ic if 1408statements apply. 1409.Pp 1410.It Ic nohup 1411.It Ic nohup Ar command 1412The first form can be used in shell scripts to cause hangups to be 1413ignored for the remainder of the script. 1414The second form causes the specified command to be run with hangups 1415ignored. 1416All processes detached with `&' are effectively 1417.Ic nohup Ns \'ed . 1418.Pp 1419.It Ic notify 1420.It Ic notify % Ns Ar job ... 1421Causes the shell to notify the user asynchronously when the status of the 1422current or specified jobs change; normally notification is presented 1423before a prompt. This is automatic if the shell variable 1424.Ic notify 1425is set. 1426.Pp 1427.It Ic onintr 1428.It Ic onintr Fl 1429.It Ic onintr Ar label 1430Control the action of the shell on interrupts. 1431The first form restores the default action of the shell on interrupts 1432which is to terminate shell scripts or to return to the terminal command 1433input level. 1434The second form `onintr \-' causes all interrupts to be ignored. 1435The final form causes the shell to execute a `goto label' when 1436an interrupt is received or a child process terminates because 1437it was interrupted. 1438.Pp 1439In any case, if the shell is running detached and interrupts are 1440being ignored, all forms of 1441.Ic onintr 1442have no meaning and interrupts 1443continue to be ignored by the shell and all invoked commands. 1444Finally 1445.Ic onintr 1446statements are ignored in the system startup files where interrupts 1447are disabled (/etc/csh.cshrc, /etc/csh.login). 1448.Pp 1449.It Ic popd 1450.It Ic popd Ar +n 1451Pops the directory stack, returning to the new top directory. 1452With an argument 1453.Ns \`+ Ar n Ns \' 1454discards the 1455.Ar n Ns \'th 1456entry in the stack. 1457The members of the directory stack are numbered from the top starting at 0. 1458.ne 1i 1459.Pp 1460.It Ic pushd 1461.It Ic pushd Ar name 1462.It Ic pushd Ar n 1463With no arguments, 1464.Ic pushd 1465exchanges the top two elements of the directory stack. 1466Given a 1467.Ar name 1468argument, 1469.Ic pushd 1470changes to the new directory (ala 1471.Ic cd ) 1472and pushes the old current working directory 1473(as in 1474.Ic csw ) 1475onto the directory stack. 1476With a numeric argument, 1477.Ic pushd 1478rotates the 1479.Ar n Ns \'th 1480argument of the directory 1481stack around to be the top element and changes to it. The members 1482of the directory stack are numbered from the top starting at 0. 1483.Pp 1484.It Ic rehash 1485Causes the internal hash table of the contents of the directories in 1486the 1487.Ic path 1488variable to be recomputed. This is needed if new commands are added 1489to directories in the 1490.Ic path 1491while you are logged in. This should only be necessary if you add 1492commands to one of your own directories, or if a systems programmer 1493changes the contents of a system directory. 1494.Pp 1495.It Ic repeat Ar count command 1496The specified 1497.Ar command 1498which is subject to the same restrictions 1499as the 1500.Ar command 1501in the one line 1502.Ic if 1503statement above, 1504is executed 1505.Ar count 1506times. 1507I/O redirections occur exactly once, even if 1508.Ar count 1509is 0. 1510.Pp 1511.It Ic set 1512.It Ic set Ar name 1513.It Ic set Ar name Ns =word 1514.It Ic set Ar name[index] Ns =word 1515.It Ic set Ar name Ns =(wordlist) 1516The first form of the command shows the value of all shell variables. 1517Variables that have other than a single word as their 1518value print as a parenthesized word list. 1519The second form sets 1520.Ar name 1521to the null string. 1522The third form sets 1523.Ar name 1524to the single 1525.Ar word . 1526The fourth form sets 1527the 1528.Ar index Ns 'th 1529component of 1530.Ar name 1531to 1532.Ar word ; 1533this component must already exist. 1534The final form sets 1535.Ar name 1536to the list of words in 1537.Ar wordlist . 1538The value is always command and filename expanded. 1539.Pp 1540These arguments may be repeated to set multiple values in a single set command. 1541Note however, that variable expansion happens for all arguments before any 1542setting occurs. 1543.Pp 1544.It Ic setenv 1545.It Ic setenv Ar name 1546.It Ic setenv Ar name value 1547The first form lists all current environment variables. 1548It is equivalent to 1549.Xr printenv 1 . 1550The last form sets the value of environment variable 1551.Ar name 1552to be 1553.Ar value , 1554a single string. The second form sets 1555.Ar name 1556to an empty string. 1557The most commonly used environment variables 1558.Ev USER , 1559.Ev TERM , 1560and 1561.Ev PATH 1562are automatically imported to and exported from the 1563.Nm csh 1564variables 1565.Ar user , 1566.Ar term , 1567and 1568.Ar path ; 1569there is no need to use 1570.Ic setenv 1571for these. 1572.Pp 1573.It Ic shift 1574.It Ic shift Ar variable 1575The members of 1576.Ic argv 1577are shifted to the left, discarding 1578.Ic argv Ns Bq 1 . 1579It is an error for 1580.Ic argv 1581not to be set or to have less than one word as value. 1582The second form performs the same function on the specified variable. 1583.Pp 1584.It Ic source Ar name 1585.It Ic source Fl h Ar name 1586.pl -1 1587The shell reads commands from 1588.Ar name . 1589.Ic Source 1590commands may be nested; if they are nested too deeply the shell may 1591run out of file descriptors. 1592An error in a 1593.Ic source 1594at any level terminates all nested 1595.Ic source 1596commands. 1597Normally input during 1598.Ic source 1599commands is not placed on the history list; 1600the \-h option causes the commands to be placed on the 1601history list without being executed. 1602.Pp 1603.It Ic stop 1604.It Ic stop % Ns Ar job ... 1605Stops the current or specified jobs that are executing in the background. 1606.Pp 1607.It Ic suspend 1608Causes the shell to stop in its tracks, much as if it had been sent a stop 1609signal with 1610.Ic ^Z . 1611This is most often used to stop shells started by 1612.Xr su 1 . 1613.Pp 1614.It Ic switch Ar (string) 1615.It Ic case Ar str1 : 1616.It \ \ \ \ \&... 1617.It Ic \ \ \ \ breaksw 1618.It \ \ \ \ \&... 1619.It Ic default : 1620.It \ \ \ \ \&... 1621.It Ic \ \ \ \ breaksw 1622.It Ic endsw 1623Each case label is successively matched against the specified 1624.Ar string 1625which is first command and filename expanded. 1626The file metacharacters `*', `?' and `[...]' 1627may be used in the case labels, 1628which are variable expanded. 1629If none of the labels match before the `default' label is found, then 1630the execution begins after the default label. 1631Each case label and the default label must appear at the beginning of a line. 1632The command 1633.Ic breaksw 1634causes execution to continue after the 1635.Ic endsw . 1636Otherwise control may fall through case labels and the default label as in C. 1637If no label matches and there is no default, execution continues after 1638the 1639.Ic endsw . 1640.Pp 1641.It Ic time 1642.It Ic time Ar command 1643With no argument, a summary of time used by this shell and its children 1644is printed. 1645If arguments are given 1646the specified simple command is timed and a time summary 1647as described under the 1648.Ic time 1649variable is printed. If necessary, an extra shell is created to print the time 1650statistic when the command completes. 1651.Pp 1652.It Ic umask 1653.It Ic umask Ar value 1654The file creation mask is displayed (first form) or set to the specified 1655value (second form). The mask is given in octal. Common values for 1656the mask are 002 giving all access to the group and read and execute 1657access to others or 022 giving all access except write access for 1658users in the group or others. 1659.Pp 1660.It Ic unalias Ar pattern 1661All aliases whose names match the specified pattern are discarded. 1662Thus all aliases are removed by `unalias *'. 1663It is not an error for nothing to be 1664.Ic unaliased . 1665.Pp 1666.It Ic unhash 1667Use of the internal hash table to speed location of executed programs 1668is disabled. 1669.Pp 1670.It Ic unlimit 1671.It Ic unlimit Ar resource 1672.It Ic unlimit Fl h 1673.It Ic unlimit Fl h Ar resource 1674Removes the limitation on 1675.Ar resource . 1676If no 1677.Ar resource 1678is specified, then all 1679.Ar resource 1680limitations are removed. If 1681.Fl h 1682is given, the corresponding hard limits are removed. Only the 1683super-user may do this. 1684.Pp 1685.It Ic unset Ar pattern 1686All variables whose names match the specified pattern are removed. 1687Thus all variables are removed by `unset *'; this has noticeably 1688distasteful side-effects. 1689It is not an error for nothing to be 1690.Ic unset . 1691.Pp 1692.It Ic unsetenv Ar pattern 1693Removes all variables whose name match the specified pattern from the 1694environment. See also the 1695.Ic setenv 1696command above and 1697.Xr printenv 1 . 1698.Pp 1699.It Ic wait 1700Wait for all background jobs. 1701If the shell is interactive, then an interrupt can disrupt the wait. 1702After the interrupt, the shell prints names and job numbers of all jobs 1703known to be outstanding. 1704.It Ic which Ar command 1705Displays the resolved command that will be executed by the shell. 1706.Pp 1707.It Ic while Ar (expr) 1708.It \&... 1709.It Ic end 1710While the specified expression evaluates non-zero, the commands between 1711the 1712.Ic while 1713and the matching 1714.Ic end 1715are evaluated. 1716.Ic Break 1717and 1718.Ic continue 1719may be used to terminate or continue the loop prematurely. 1720(The 1721.Ic while 1722and 1723.Ic end 1724must appear alone on their input lines.) 1725Prompting occurs here the first time through the loop as for the 1726.Ic foreach 1727statement if the input is a terminal. 1728.Pp 1729.It Ic % Ns Ar job 1730Brings the specified job into the foreground. 1731.Pp 1732.It Ic % Ns Ar job Ic & 1733Continues the specified job in the background. 1734.Pp 1735.It Ic @ 1736.It Ic @ Ns Ar name Ns = expr 1737.It Ic @ Ns Ar name[index] Ns = expr 1738The first form prints the values of all the shell variables. 1739The second form sets the specified 1740.Ar name 1741to the value of 1742.Ar expr . 1743If the expression contains `<', `>', `&' or `|' then at least 1744this part of the expression must be placed within `(' `)'. 1745The third form assigns the value of 1746.Ar expr 1747to the 1748.Ar index Ns 'th 1749argument of 1750.Ar name . 1751Both 1752.Ar name 1753and its 1754.Ar index Ns 'th 1755component must already exist. 1756.El 1757.Pp 1758The operators `*=', `+=', etc are available as in C. 1759The space separating the name from the assignment operator is optional. 1760Spaces are, however, mandatory in separating components of 1761.Ar expr 1762which would otherwise be single words. 1763.Pp 1764Special postfix `+\|+' and `\-\|\-' operators increment and decrement 1765.Ar name 1766respectively, i.e., `@ i++'. 1767.Ss Pre-defined and environment variables 1768The following variables have special meaning to the shell. 1769Of these, 1770.Ar argv , 1771.Ar cwd, 1772.Ar home , 1773.Ar path, 1774.Ar prompt , 1775.Ar shell 1776and 1777.Ar status 1778are always set by the shell. 1779Except for 1780.Ar cwd 1781and 1782.Ar status , 1783this setting occurs only at initialization; 1784these variables will not then be modified unless done 1785explicitly by the user. 1786.Pp 1787The shell copies the environment variable 1788.Ev USER 1789into the variable 1790.Ar user , 1791.Ev TERM 1792into 1793.Ar term , 1794and 1795.Ev HOME 1796into 1797.Ar home , 1798and copies these back into the environment whenever the normal 1799shell variables are reset. 1800The environment variable 1801.Ev PATH 1802is likewise handled; it is not 1803necessary to worry about its setting other than in the file 1804.Ar \&.cshrc 1805as inferior 1806.Nm csh 1807processes will import the definition of 1808.Ar path 1809from the environment, and re-export it if you then change it. 1810.ne 1i 1811.Bl -tag -width histchars 1812.It Ic argv 1813Set to the arguments to the shell, it is from this variable that 1814positional parameters are substituted, i.e., `$1' is replaced by 1815`$argv[1]', 1816etc. 1817.It Ic cdpath 1818Gives a list of alternate directories searched to find subdirectories 1819in 1820.Ar chdir 1821commands. 1822.It Ic cwd 1823The full pathname of the current directory. 1824.It Ic echo 1825Set when the 1826.Fl x 1827command line option is given. 1828Causes each command and its arguments 1829to be echoed just before it is executed. 1830For non-builtin commands all expansions occur before echoing. 1831Builtin commands are echoed before command and filename substitution, 1832since these substitutions are then done selectively. 1833.It Ic filec 1834Enable file name completion. 1835.It Ic histchars 1836Can be given a string value to change the characters used in history 1837substitution. The first character of its value is used as the 1838history substitution character, replacing the default character `!'. 1839The second character of its value replaces the character `\(ua' in 1840quick substitutions. 1841.It Ic histfile 1842Can be set to the pathname where history is going to be saved/restored. 1843.It Ic history 1844Can be given a numeric value to control the size of the history list. 1845Any command that has been referenced in this many events will not be 1846discarded. 1847Too large values of 1848.Ar history 1849may run the shell out of memory. 1850The last executed command is always saved on the history list. 1851.It Ic home 1852The home directory of the invoker, initialized from the environment. 1853The filename expansion of 1854.Sq Pa ~ 1855refers to this variable. 1856.It Ic ignoreeof 1857If set the shell ignores 1858end-of-file from input devices which are terminals. 1859This prevents shells from accidentally being killed by control-D's. 1860.It Ic mail 1861The files where the shell checks for mail. 1862This checking is done after each command completion that will 1863result in a prompt, 1864if a specified interval has elapsed. 1865The shell says `You have new mail.' 1866if the file exists with an access time not greater than its modify time. 1867.Pp 1868If the first word of the value of 1869.Ar mail 1870is numeric it specifies a different mail checking interval, in seconds, 1871than the default, which is 10 minutes. 1872.Pp 1873If multiple mail files are specified, then the shell says 1874`New mail in 1875.Ar name Ns ' 1876when there is mail in the file 1877.Ar name . 1878.It Ic noclobber 1879As described in the section on 1880.Sx input/output , 1881restrictions are placed on output redirection to insure that 1882files are not accidentally destroyed, and that `>>' redirections 1883refer to existing files. 1884.It Ic noglob 1885If set, filename expansion is inhibited. 1886This inhibition is most useful in shell scripts that 1887 are not dealing with filenames, 1888or after a list of filenames has been obtained and further expansions 1889are not desirable. 1890.It Ic nonomatch 1891If set, it is not an error for a filename expansion to not match any 1892existing files; instead the primitive pattern is returned. 1893It is still an error for the primitive pattern to be malformed, i.e., 1894`echo [' 1895still gives an error. 1896.It Ic notify 1897If set, the shell notifies asynchronously of job completions; 1898the default is to present job completions just before printing 1899a prompt. 1900.It Ic path 1901Each word of the path variable specifies a directory in which 1902commands are to be sought for execution. 1903A null word specifies the current directory. 1904If there is no 1905.Ar path 1906variable then only full path names will execute. 1907The usual search path is `.', `/bin' and `/usr/bin', but this 1908may vary from system to system. 1909For the super-user the default search path is `/etc', `/bin' and `/usr/bin'. 1910A shell that is given neither the 1911.Fl c 1912nor the 1913.Fl t 1914option will normally hash the contents of the directories in the 1915.Ar path 1916variable after reading 1917.Ar \&.cshrc , 1918and each time the 1919.Ar path 1920variable is reset. If new commands are added to these directories 1921while the shell is active, it may be necessary to do a 1922.Ic rehash 1923or the commands may not be found. 1924.It Ic prompt 1925The string that is printed before each command is read from 1926an interactive terminal input. 1927If a `!' appears in the string it will be replaced by the current event number 1928unless a preceding `\e' is given. 1929Default is `% ', or `# ' for the super-user. 1930.It Ic savehist 1931Is given a numeric value to control the number of entries of the 1932history list that are saved in ~/.history when the user logs out. 1933Any command that has been referenced in this many events will be saved. 1934During start up the shell sources ~/.history into the history list 1935enabling history to be saved across logins. 1936Too large values of 1937.Ar savehist 1938will slow down the shell during start up. 1939If 1940.Ar savehist 1941is just set, the shell will use the value of 1942.Ar history. 1943.It Ic shell 1944The file in which the shell resides. 1945This variable is used in forking shells to interpret files that have execute 1946bits set, but which are not executable by the system. 1947(See the description of 1948.Sx Non-builtin Command Execution 1949below.) 1950Initialized to the (system-dependent) home of the shell. 1951.It Ic status 1952The status returned by the last command. 1953If it terminated abnormally, then 0200 is added to the status. 1954Builtin commands that fail return exit status `1', 1955all other builtin commands set status to `0'. 1956.It Ic time 1957Controls automatic timing of commands. 1958If set, then any command that takes more than this many cpu seconds 1959will cause a line giving user, system, and real times and a utilization 1960percentage which is the ratio of user plus system times to real time 1961to be printed when it terminates. 1962.It Ic verbose 1963Set by the 1964.Fl v 1965command line option, causes the words of each command to be printed 1966after history substitution. 1967.El 1968.Ss Non-builtin command execution 1969When a command to be executed is found to not be a builtin command 1970the shell attempts to execute the command via 1971.Xr execve 2 . 1972Each word in the variable 1973.Ar path 1974names a directory from which the shell will attempt to execute the command. 1975If it is given neither a 1976.Fl c 1977nor a 1978.Fl t 1979option, the shell will hash the names in these directories into an internal 1980table so that it will only try an 1981.Ic exec 1982in a directory if there is a possibility that the command resides there. 1983This shortcut greatly speeds command location when many directories 1984are present in the search path. 1985If this mechanism has been turned off (via 1986.Ic unhash ) , 1987or if the shell was given a 1988.Fl c 1989or 1990.Fl t 1991argument, and in any case for each directory component of 1992.Ar path 1993that does not begin with a `/', 1994the shell concatenates with the given command name to form a path name 1995of a file which it then attempts to execute. 1996.Pp 1997Parenthesized commands are always executed in a subshell. 1998Thus 1999.Pp 2000.Dl (cd ; pwd) ; pwd 2001.Pp 2002prints the 2003.Ar home 2004directory; leaving you where you were (printing this after the home directory), 2005while 2006.Pp 2007.Dl cd ; pwd 2008.Pp 2009leaves you in the 2010.Ar home 2011directory. 2012Parenthesized commands are most often used to prevent 2013.Ic chdir 2014from affecting the current shell. 2015.Pp 2016If the file has execute permissions but is not an 2017executable binary to the system, then it is assumed to be a 2018file containing shell commands and a new shell is spawned to read it. 2019.pl +1 2020.Pp 2021If there is an 2022.Ic alias 2023for 2024.Ic shell 2025then the words of the alias will be prepended to the argument list to form 2026the shell command. 2027The first word of the 2028.Ic alias 2029should be the full path name of the shell 2030(e.g., `$shell'). 2031Note that this is a special, late occurring, case of 2032.Ic alias 2033substitution, 2034and only allows words to be prepended to the argument list without change. 2035.ne 1i 2036.Ss Signal handling 2037The shell normally ignores 2038.Ar quit 2039signals. 2040Jobs running detached (either by 2041.Ic \&& 2042or the 2043.Ic bg 2044or 2045.Ic %... & 2046commands) are immune to signals generated from the keyboard, including 2047hangups. 2048Other signals have the values which the shell inherited from its parent. 2049The shell's handling of interrupts and terminate signals 2050in shell scripts can be controlled by 2051.Ic onintr . 2052Login shells catch the 2053.Ar terminate 2054signal; otherwise this signal is passed on to children from the state in the 2055shell's parent. 2056Interrupts are not allowed when a login shell is reading the file 2057.Pa \&.logout . 2058.Sh AUTHOR 2059William Joy. 2060Job control and directory stack features first implemented by J.E. Kulp of 2061IIASA, Laxenburg, Austria, 2062with different syntax than that used now. 2063File name completion code written by Ken Greer, HP Labs. 2064Eight-bit implementation Christos S. Zoulas, Cornell University. 2065.Sh FILES 2066.Bl -tag -width /etc/passwd -compact 2067.It Pa ~/.cshrc 2068Read at beginning of execution by each shell. 2069.It Pa ~/.login 2070Read by login shell, after `.cshrc' at login. 2071.It Pa ~/.logout 2072Read by login shell, at logout. 2073.It Pa /bin/sh 2074Standard shell, for shell scripts not starting with a `#'. 2075.It Pa /tmp/sh* 2076Temporary file for `<<'. 2077.It Pa /etc/passwd 2078Source of home directories for `~name'. 2079.El 2080.Sh LIMITATIONS 2081Word lengths \- 2082Words can be no longer than 1024 characters. 2083The system limits argument lists to 10240 characters. 2084The number of arguments to a command that involves filename expansion 2085is limited to 1/6'th the number of characters allowed in an argument list. 2086Command substitutions may substitute no more characters than are 2087allowed in an argument list. 2088To detect looping, the shell restricts the number of 2089.Ic alias 2090substitutions on a single line to 20. 2091.Sh SEE ALSO 2092.Xr sh 1 , 2093.Xr access 2 , 2094.Xr execve 2 , 2095.Xr fork 2 , 2096.Xr killpg 2 , 2097.Xr pipe 2 , 2098.Xr sigvec 2 , 2099.Xr umask 2 , 2100.Xr setrlimit 2 , 2101.Xr wait 2 , 2102.Xr tty 4 , 2103.Xr a.out 5 , 2104.Xr environ 7 , 2105.br 2106.Em An introduction to the C shell 2107.Sh HISTORY 2108.Nm Csh 2109appeared in 2110.Bx 3 . 2111It 2112was a first implementation of a command language interpreter 2113incorporating a history mechanism (see 2114.Sx History Substitutions ) , 2115job control facilities (see 2116.Sx Jobs ) , 2117interactive file name 2118and user name completion (see 2119.Sx File Name Completion ) , 2120and a C-like syntax. 2121There are now many shells that also have these mechanisms, plus 2122a few more (and maybe some bugs too), which are available through the 2123usenet. 2124.Sh BUGS 2125When a command is restarted from a stop, 2126the shell prints the directory it started in if this is different 2127from the current directory; this can be misleading (i.e., wrong) 2128as the job may have changed directories internally. 2129.Pp 2130Shell builtin functions are not stoppable/restartable. 2131Command sequences of the form `a ; b ; c' are also not handled gracefully 2132when stopping is attempted. If you suspend `b', the shell will 2133immediately execute `c'. This is especially noticeable if this 2134expansion results from an 2135.Ar alias . 2136It suffices to place the sequence of commands in ()'s to force it to 2137a subshell, i.e., `( a ; b ; c )'. 2138.Pp 2139Control over tty output after processes are started is primitive; 2140perhaps this will inspire someone to work on a good virtual 2141terminal interface. In a virtual terminal interface much more 2142interesting things could be done with output control. 2143.Pp 2144Alias substitution is most often used to clumsily simulate shell procedures; 2145shell procedures should be provided instead of aliases. 2146.Pp 2147Commands within loops, prompted for by `?', are not placed on the 2148.Ic history 2149list. 2150Control structure should be parsed instead of being recognized as built-in 2151commands. This would allow control commands to be placed anywhere, 2152to be combined with `\&|', and to be used with `&' and `;' metasyntax. 2153.Pp 2154It should be possible to use the `:' modifiers on the output of command 2155substitutions. 2156.Pp 2157The way the 2158.Ic filec 2159facility is implemented is ugly and expensive. 2160