NEWCSH(1) UNIX Programmer's Manual NEWCSH(1) NAME newcsh - description of new csh features (over oldcsh) SYNOPSIS csh _c_s_h-_o_p_t_i_o_n_s SUMMARY This is a summary of features new in _c_s_h(1) in this version of the system; an older version of _c_s_h is available as _o_l_d_c_s_h. This newer _c_s_h has some new process control primi- tives and a few other new features. Users of _c_s_h must (and automatically) use the new terminal driver (summarized in _n_e_w_t_t_y(_4) and completely described with the old in _t_t_y(4)) which allows generation of some new interrupt signals from the keyboard which tell jobs to stop, and arbitrates access to the terminal; on CRT's the command ``stty crt'' is nor- mally placed in the ._l_o_g_i_n file to be executed at login, to set other useful modes of this terminal driver. Jobs. The most important new feature in this shell is the control of _j_o_b_s. A job is associated with each pipeline, where a pipeline is either a simple command like ``date'', or a pipeline like ``who | wc''. The shell keeps a table of current jobs, and assigns them small integer numbers. When you start a job in the background, the shell prints a line which looks like: [1] 1234 this indicating that the job which was started asynchro- nously with ``&'' is job number 1 and has one (top-level) process, whose process id is 1234. The set of current jobs is listed by the _j_o_b_s command. If you are running a job and wish to do something else you may hit the key ^Z (control-Z) which sends a _s_t_o_p signal to the current job. The shell will then normally indicate that the job has been ``Stopped'', and print another prompt. You can then put the job in the background with the command ``bg'', or run some other commands and then return the job to the foreground with ``fg''. A ^Z takes effect immedi- ately and is like an interrupt in that pending output and unread input are discarded when it is typed. There is another special key ^Y which does not generate a stop signal until a program attempts to _r_e_a_d(2) it. This can usefully be typed ahead when you have prepared some commands for a job which you wish to stop after it has read them. A job being run in the background will stop if it tries to read from the terminal. Background jobs are normally Printed 5/16/83 1 NEWCSH(1) UNIX Programmer's Manual NEWCSH(1) allowed to produce output, but this can be disabled by doing ``stty tostop''. If you set this tty option, then back- ground jobs will stop when they try to produce output like they do when they try to read input. There are several ways to refer to jobs in the shell. The character ``%'' introduces a job name. If you wish to refer to job number 1, you can name it as ``%1''. Just naming a job brings it to the foreground; thus ``%1'' is a synonym for ``fg %1'', bringing job 1 back into the foreground. Similarly saying ``%1 &'' resumes job 1 in the background. Jobs can also be named by prefixes of the string typed in to start them, if these prefixes are unambiguous, thus ``%ex'' would normally restart a suspended _e_x(1) job, if there were only one suspended job whose name began with the string ``ex''. It is also possible to say ``%?string'' which specifies a job whose text contains _s_t_r_i_n_g, if there is only one such job. The shell also maintains a notion of the current and previ- ous jobs. In output pertaining to jobs, the current job is marked with a ``+'' and the previous job with a ``-''. The abbreviation ``%+'' refers to the current job and ``%-'' refers to the previous job. For close analogy with the _h_i_s_- _t_o_r_y mechanism, ``%%'' is also a synonym for the current job. Status reporting. This shell learns immediately whenever a process changes state. It normally informs you whenever a job becomes blocked so that no further progress is possible, but only just before it prints a prompt. This is done so that it does not otherwise disturb your work. If, however, you set the shell variable _n_o_t_i_f_y, the shell will notify you immedi- ately of changes of status in background jobs. There is also a shell command _n_o_t_i_f_y which marks a single process so that its status changes will be immediately reported. By default _n_o_t_i_f_y marks the current process; simply say ``notify'' after starting a background job to mark it. When you try to leave the shell while jobs are stopped, you will be warned that ``You have stopped jobs.'' You may use the ``jobs'' command to see what they are. If you do this or immediately try to exit again, the shell will not warn you a second time, and the suspended jobs will be unmerci- fully terminated. New builtin commands. bg Printed 5/16/83 2 NEWCSH(1) UNIX Programmer's Manual NEWCSH(1) bg %job ... Puts the current or specified jobs into the background, continuing them if they were stopped. fg fg %job ... Brings the current or specified jobs into the fore- ground, continuing them if they were stopped. jobs jobs -l Lists the active jobs; given the -l options lists pro- cess id's in addition to the normal information. kill %job kill -sig %job ... kill pid kill -sig pid ... kill -l Sends either the TERM (terminate) signal or the speci- fied signal to the specified jobs or processes. Sig- nals are either given by number or by names (as given in /_u_s_r/_i_n_c_l_u_d_e/_s_i_g_n_a_l._h, stripped of the prefix ``SIG''). The signal names are listed by ``kill -l''. There is no default, saying just `kill' does not send a signal to the current job. If the signal being sent is TERM (terminate) or HUP (hangup), then the job or pro- cess will be sent a CONT (continue) signal as well. notify notify %job ... Causes the shell to notify the user asynchronously when the status of the current or specified jobs changes; normally notification is presented before a prompt. All jobs are marked ``notify'' if the shell variable ``notify'' is set. stop %job ... Stops the specified job which is executing in the back- ground. %job Brings the specified job into the foreground. %job & Continues the specified job in the background. Process limitations. The shell provides access (on VAX-11 systems) to an experi- mental facility for limiting the consumption by a single process of system resources. The following commands control Printed 5/16/83 3 NEWCSH(1) UNIX Programmer's Manual NEWCSH(1) this facility: limit _r_e_s_o_u_r_c_e _m_a_x_i_m_u_m-_u_s_e limit _r_e_s_o_u_r_c_e limit Limits the consumption by the current process and each process it creates to not individually exceed _m_a_x_i_m_u_m- _u_s_e 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 the current limit is printed; if no _r_e_s_o_u_r_c_e is given, then all limitations are given. Resources controllable currently include _c_p_u_t_i_m_e (the maximum number of cpu-seconds to be used by each pro- cess), _f_i_l_e_s_i_z_e (the largest single file which can be created), _d_a_t_a_s_i_z_e (the maximum growth of the data+stack region via _s_b_r_k(2) beyond the end of the program text), _s_t_a_c_k_s_i_z_e (the maximum size of the automatically-extended stack region), and _c_o_r_e_d_u_m_p_s_i_z_e (the size of the largest core dump that will be created). The _m_a_x_i_m_u_m-_u_s_e may be given as a (floating point or integer) number followed by a scale factor. For all limits other than _c_p_u_t_i_m_e the default scale is ``k'' or ``kilobytes'' (1024 bytes); a scale factor of ``m'' or ``megabytes'' may also be used. For cputime the default scaling is ``seconds'', while ``m'' for minutes or ``h'' for hours, or a time of the form ``mm:ss'' giving minutes and seconds may be used. For both _r_e_s_o_u_r_c_e names and scale factors, unambiguous prefixes of the names suffice. unlimit _r_e_s_o_u_r_c_e unlimit Removes the limitation on _r_e_s_o_u_r_c_e. If no _r_e_s_o_u_r_c_e is specified, then all _r_e_s_o_u_r_c_e limitations are removed. Directory stack. This shell now keeps track of the current directory (which is kept in the variable _c_w_d) and also maintains a stack of directories, which is printed by the command _d_i_r_s. You can change to a new directory and push down the old directory stack by using the command _p_u_s_h_d which is otherwise like the _c_h_d_i_r command, changing to its argument. You can pop the directory stack by saying _p_o_p_d. Saying _p_u_s_h_d with no argu- ments exchanges the top two elements of the directory stack. The elements of the directory stack are numbered from 1 starting at the top. Saying _p_u_s_h_d with a argument ``+_n'' rotates the directory stack to make that entry in the stack Printed 5/16/83 4 NEWCSH(1) UNIX Programmer's Manual NEWCSH(1) be at the top and changes to it. Giving _p_o_p_d a ``+_n'' argu- ment eliminates that argument from the directory stack. Miscellaneous. This shell imports the environment variable USER into the variable _u_s_e_r, TERM into _t_e_r_m, and HOME into _h_o_m_e, and exports these back into the environment whenever the normal shell variables are reset. The environment variable PATH is likewise handled; it is not necessary to worry about its setting other than in the file ._c_s_h_r_c as inferior _c_s_h processes will import the definition of _p_a_t_h from the environment, and re-export it if you then change it. (It could be set once in the ._l_o_g_i_n except that commands over the Berknet would not see the definition.) There are new commands _e_v_a_l, which is like the eval of the Bourne shell _s_h(1), and useful with _t_s_e_t(1), and _s_u_s_p_e_n_d which stops a shell (as though a ^Z had stopped it; since shells normally ignore ^Z signals, this command is neces- sary.) There is a new variable _c_d_p_a_t_h; if set, then each directory in _c_d_p_a_t_h will be searched for a directory named in a _c_h_d_i_r command if there is no such subdirectory of the current directory. An _u_n_s_e_t_e_n_v command removing environment variables has been added. There is a new ``:'' modifier ``:e'', which yields the extension portion of a filename. Thus if ``$a'' is ``file.c'', ``$a:e'' is ``c''. There are two new operators in shell expressions ``!~'' and ``=~'' which are like the string operations ``!='' and ``=='' except that the right hand side is a _p_a_t_t_e_r_n (con- taining, e.g. ``*''s, ``?''s and instances of ``[...]'') against which the left hand operand is matched. This reduces the need for use of the _s_w_i_t_c_h statement in shell scripts when all that is really needed is pattern matching. The form ``$<'' is new, and is replaced by a line from the standard input, with no further interpretation thereafter. It may therefore be used to read from the keyboard in a shell script. SEE ALSO csh(1), killpg(2), signal(2), sigsys(2), jobs(3), sigset(3), tty(4) Printed 5/16/83 5 NEWCSH(1) UNIX Programmer's Manual NEWCSH(1) BUGS Command sequences of the form ``a ; b ; c'' are not handled gracefully when stopping is attempted. If you suspend ``b'', the shell will then immediately execute ``c''. This is especially noticeable if this expansion results from an _a_l_i_a_s. It suffices to place the sequence of commands in ()'s to force it to a subshell, i.e. ``( a ; b ; c )'', but see the next bug. Shell builtin functions are not stoppable/restartable. Control over output is primitive; perhaps this will inspire someone to work on a good virtual terminal interface. In a virtual terminal interface much more interesting things could be done with output control. Printed 5/16/83 6