[UnixCompendium] / trunk / unix.info-2 Repository:
ViewVC logotype

Annotation of /trunk/unix.info-2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : root 1 This is unix.info, produced by makeinfo version 4.0 from unix.texinfo.
2 :    
3 :     
4 :     File: unix.info, Node: Regular expressions, Next: Nested shells and reverse apostrophes, Prev: Wildcards, Up: Shells
5 :    
6 :     Regular expressions
7 :     -------------------
8 :    
9 :     The wildcards belong to the shell. They are used for matching
10 :     filenames. UNIX has a more general and widely used mechanism for
11 :     matching _strings_, this is through _regular expressions_.
12 :    
13 :     Regular expressions are used by the `egrep' utility, text editors
14 :     like `ed', `vi' and `emacs' and `sed' and `awk'. They are also used in
15 :     the C programming language for matching input as well as in the Perl
16 :     programming language and `lex' tokenizer. Here are some examples using
17 :     the `egrep' command which print lines from the file `/etc/rc' which
18 :     match certain conditions. The `' contruction is part of `egrep'.
19 :     Everything in between these symbols is a regular expression. Notice that
20 :     special shell symbols `! * &' have to be preceded with a backslash `\'
21 :     in order to prevent the shell from expanding them!
22 :    
23 :    
24 :     # Print all lines beginning with a comment #
25 :    
26 :     egrep '(^#)' /etc/rc
27 :    
28 :     # Print all lines which DON'T begin with #
29 :    
30 :     egrep '(^[^#])' /etc/rc
31 :    
32 :     # Print all lines beginning with e, f or g.
33 :    
34 :     egrep '(^[efg])' /etc/rc
35 :    
36 :     # Print all lines beginning with uppercase
37 :    
38 :     egrep '(^[A-Z])' /etc/rc
39 :    
40 :     # Print all lines NOT beginning with uppercase
41 :    
42 :     egrep '(^[^A-Z])' /etc/rc
43 :    
44 :     # Print all lines containing ! * &
45 :    
46 :     egrep '([\!\*\&])' /etc/rc
47 :    
48 :     # All lines containing ! * & but not starting #
49 :    
50 :     egrep '([^#][\!\*\&])' /etc/rc
51 :    
52 :     Regular expressions are made up of the following `atoms'.
53 :    
54 :     These examples assume that the file `/etc/rc' exists. If it doesn't
55 :     exist on the machine you are using, try to find the equivalent by, for
56 :     instance, replacing `/etc/rc' with `/etc/rc*' which will try to find a
57 :     match beginning with the rc.
58 :    
59 :     `.'
60 :     Match any single character except the end of line.
61 :    
62 :     `^'
63 :     Match the beginning of a line as the first character.
64 :    
65 :     `$'
66 :     Match end of line as last character.
67 :    
68 :     `[..]'
69 :     Match any character in the list between the square brackets.(see
70 :     below).
71 :    
72 :     `*'
73 :     Match zero or more occurrances of the preceding expression.
74 :    
75 :     `+'
76 :     Match one or more occurrences of the preceding expression.
77 :    
78 :     `?'
79 :     Match zero or one occurrance of the preceding expression.
80 :    
81 :     You can find a complete list in the unix manual pages. The square
82 :     brackets above are used to define a _class_ of characters to be
83 :     matched. Here are some examples,
84 :    
85 :     * If the square brackets contain a list of characters, $[a-z156]$
86 :     then a single occurrance of any character in the list will match
87 :     the regular expression: in this case any lowercase letter or the
88 :     numbers 1, 5 and 6.
89 :    
90 :     * If the first character in the brackets is the caret symbol `^'
91 :     then any character _except_ those in the list will be matched.
92 :    
93 :     * Normally a dash or minus sign `-' means a range of characters. If
94 :     it is the first character after the `[' or after `[^' then it is
95 :     treated literally.
96 :    
97 :     
98 :     File: unix.info, Node: Nested shells and reverse apostrophes, Prev: Regular expressions, Up: Shells
99 :    
100 :     Nested shell commands and "
101 :     ---------------------------
102 :    
103 :     The backwards apostrophes `...` can be used in all shells and also in
104 :     the programming language Perl. When these are encountered in a string
105 :     the shell tries to execute the command inside the quotes and replace
106 :     the quoted expression by the result of that command. For example:
107 :     unix% echo "This system's kernel type is `/bin/file /vmunix`"
108 :     This system's kernel type is /vmunix: sparc executable not stripped
109 :    
110 :     unix% foreach file ( `ls /etc/rc*` )
111 :     ? echo I found a config file $file
112 :     ? echo Its type is `/bin/file $file`
113 :     ? end
114 :    
115 :     I found a config file /etc/rc
116 :     Its type is /etc/rc: executable shell script
117 :     I found a config file /etc/rc.boot
118 :     Its type is /etc/rc.boot: executable shell script
119 :     I found a config file /etc/rc.ip
120 :     Its type is /etc/rc.ip: executable shell script
121 :     I found a config file /etc/rc.local
122 :     Its type is /etc/rc.local: ascii text
123 :     I found a config file /etc/rc.local~
124 :     Its type is /etc/rc.local~: ascii text
125 :     I found a config file /etc/rc.single
126 :     Its type is /etc/rc.single: executable shell script
127 :     I found a config file /etc/rc~
128 :     Its type is /etc/rc~: executable shell script
129 :    
130 :     This is how we insert the result of a shell command into a text
131 :     string or variable.
132 :    
133 :     
134 :     File: unix.info, Node: UNIX command overview, Next: Terminals, Prev: Shells, Up: The login environment
135 :    
136 :     UNIX command overview
137 :     =====================
138 :    
139 :     * Menu:
140 :    
141 :     * Keys::
142 :     * Alternative shells::
143 :     * terminal emulators::
144 :     * Remote login::
145 :     * Text editors::
146 :     * File handling::
147 :     * File browsers::
148 :     * Access control::
149 :     * Extracting from files::
150 :     * Locating files::
151 :     * Disk usage::
152 :     * Other users::
153 :     * Contacting users::
154 :     * Mail::
155 :     * File transfer::
156 :     * Compilers::
157 :     * Interpreted languages::
158 :     * System statistics::
159 :     * System identity::
160 :     * Internet resources::
161 :     * Text/postscript::
162 :     * Pictures/graphics::
163 :     * Miscellaneous::
164 :    
165 :     
166 :     File: unix.info, Node: Keys, Next: Alternative shells, Prev: UNIX command overview, Up: UNIX command overview
167 :    
168 :     Important keys
169 :     --------------
170 :    
171 :     <CTRL-A>
172 :     Jump to start of line. If `screen' is active, this prefixes all
173 :     control key commands for `screen' and then the normal `CTRL-A' is
174 :     replaced by `CTRL-a a'.
175 :    
176 :     <CTRL-C>
177 :     Interrupt or break key. Sends signal 15 to a process.
178 :    
179 :     <CTRL-D>
180 :     Signifies `EOF' (end of file) or shows expansion matches in
181 :     command/filename completion *Note Command/filename completion::.
182 :    
183 :     <CTRL-E>
184 :     Jump to end of line.
185 :    
186 :     <CTRL-L>
187 :     Clear screen in newer shells and in emacs. Same as `clear' in the
188 :     shell.
189 :    
190 :     <CTRL-Z>
191 :     Suspend the present process, but do not destroy it. This sends
192 :     signal 18 to the process.
193 :    
194 :     
195 :     File: unix.info, Node: Alternative shells, Next: terminal emulators, Prev: Keys, Up: UNIX command overview
196 :    
197 :     Alternative shells
198 :     ------------------
199 :    
200 :     `bash'
201 :     The Bourne Again shell, an improved sh.
202 :    
203 :     `csh'
204 :     The standard C-shell.
205 :    
206 :     `jsh'
207 :     The same as sh, with C-shell style job control.
208 :    
209 :     `ksh'
210 :     The Korn shell, an improved sh.
211 :    
212 :     `sh'
213 :     The original Bourne shell.
214 :    
215 :     `sh5'
216 :     On ULTRIX systems the standard Bourne shell is quite stupid. sh5
217 :     corresponds to the normal Bourne shell on these systems.
218 :    
219 :     `tcsh'
220 :     An improved C-shell.
221 :    
222 :     `zsh'
223 :     An improved sh.
224 :    
225 :     
226 :     File: unix.info, Node: terminal emulators, Next: Remote login, Prev: Alternative shells, Up: UNIX command overview
227 :    
228 :     Window based terminal emulators
229 :     -------------------------------
230 :    
231 :     `xterm'
232 :     The standard X11 terminal window.
233 :    
234 :     `shelltool, cmdtool'
235 :     Openwindows terminals from Sun Microsystems. These are not
236 :     completely X11 compatible during copy/paste operations.
237 :    
238 :     `screen'
239 :     This is not a window in itself, but allows you to emulate having
240 :     several windows inside a single (say) xterm window. The user can
241 :     switch between different windows and open new ones, but can only
242 :     see one window at a time *Note Multiple screens::.
243 :    
244 :     
245 :     File: unix.info, Node: Remote login, Next: Text editors, Prev: terminal emulators, Up: UNIX command overview
246 :    
247 :     Remote shells and logins
248 :     ------------------------
249 :    
250 :     `rlogin'
251 :     Login onto a remote unix system.
252 :    
253 :     `rsh'
254 :     Open a shell on a remote system (require access rights).
255 :    
256 :     `telnet'
257 :     Open a connection to a remove system using the telnet protocol.
258 :    
259 :     
260 :     File: unix.info, Node: Text editors, Next: File handling, Prev: Remote login, Up: UNIX command overview
261 :    
262 :     Text editors
263 :     ------------
264 :    
265 :     `ed'
266 :     An ancient line-editor.
267 :    
268 :     `vi'
269 :     Visual interface to `ed'. This is the only "standard" unix text
270 :     editor supplied by vendors.
271 :    
272 :     `emacs'
273 :     The most powerful UNIX editor. A fully configurable, user
274 :     programmable editor which works under X11 and on tty-terminals.
275 :    
276 :     `xemacs'
277 :     A pretty version of emacs for X11 windows.
278 :    
279 :     `pico'
280 :     A tty-terminal only editor, comes as part of the PINE mail package.
281 :    
282 :     `xedit'
283 :     A test X11-only editor supplied with X-windows.
284 :    
285 :     `textedit'
286 :     A simple X11-only editor supplied by Sun Microsystems.
287 :    
288 :     
289 :     File: unix.info, Node: File handling, Next: File browsers, Prev: Text editors, Up: UNIX command overview
290 :    
291 :     File handling commands
292 :     ----------------------
293 :    
294 :     `ls'
295 :     List files in specified directory (like `dir' on other systems).
296 :    
297 :     `cp'
298 :     Copy files.
299 :    
300 :     `mv'
301 :     Move or rename files.
302 :    
303 :     `touch'
304 :     Creates an empty new file if none exists, or updates date and time
305 :     stamps on existing files.
306 :    
307 :     `rm, unlink'
308 :     Remove a file or link (delete).
309 :    
310 :     `mkdir, rmdir'
311 :     Make or remove a directory. A directory must be empty in order to
312 :     be able to remove it.
313 :    
314 :     `cat'
315 :     Concatenate or join together a number of files. The output is
316 :     written to the standard output by default. Can also be used to
317 :     simply print a file on screen.
318 :    
319 :     `lp, lpr'
320 :     Line printer. Send a file to the default printer, or the printer
321 :     defined in the `PRINTER' evironment variable.
322 :    
323 :     `lpq, lpstat'
324 :     Show the status of the print queue.
325 :    
326 :     
327 :     File: unix.info, Node: File browsers, Next: Access control, Prev: File handling, Up: UNIX command overview
328 :    
329 :     File browsing
330 :     -------------
331 :    
332 :     `more'
333 :     Shows one screen full at a time. Possibility to search for a
334 :     string and edit the file. This is like `type FILE | more' in DOS.
335 :    
336 :     `less'
337 :     An enhanced version of more.
338 :    
339 :     `mc'
340 :     Midnight commander, a free version of the `Norton Commander' PC
341 :     utility for unix. (Only for non-serious UNIX users...)
342 :    
343 :     `fmgr'
344 :     A window based file manager with icons and all that nonsense.
345 :    
346 :     
347 :     File: unix.info, Node: Access control, Next: Extracting from files, Prev: File browsers, Up: UNIX command overview
348 :    
349 :     Ownership and granting access permission
350 :     ----------------------------------------
351 :    
352 :     `chmod'
353 :     Change file access mode.
354 :    
355 :     `chown, chgrp'
356 :     Change owner and group of a file. The GNU version of `chown'
357 :     allows both these operations to be performed together using the
358 :     syntax `chown OWNER.GROUP FILE'.
359 :    
360 :     `acl'
361 :     On newer Unices, Access control lists allow access to be granted
362 :     on a per-user basis rather than by groups.
363 :    
364 :     
365 :     File: unix.info, Node: Extracting from files, Next: Locating files, Prev: Access control, Up: UNIX command overview
366 :    
367 :     Extracting from and rebuilding files
368 :     ------------------------------------
369 :    
370 :     `cut'
371 :     Extract a column in a table
372 :    
373 :     `paste'
374 :     Merge several files so that each file becomes a column in a table.
375 :    
376 :     `sed'
377 :     A batch text-editor for searching, replacing and selecting text
378 :     without human intervention.
379 :    
380 :     `awk'
381 :     A prerunner to the Perl language, for extracting and modifying
382 :     textfiles.
383 :    
384 :     `rmcr'
385 :     Strip carriage return (ASCII 13) characters from a file. Useful
386 :     for converting DOS files to unix.
387 :    
388 :     
389 :     File: unix.info, Node: Locating files, Next: Disk usage, Prev: Extracting from files, Up: UNIX command overview
390 :    
391 :     Locating files
392 :     --------------
393 :    
394 :     `find'
395 :     Search for files from a specified directory using various criteria.
396 :    
397 :     `locate'
398 :     Fast search in a global file database for files containing a
399 :     search-string.
400 :    
401 :     `whereis'
402 :     Look for a command and its documentation on the system.
403 :    
404 :     
405 :     File: unix.info, Node: Disk usage, Next: Other users, Prev: Locating files, Up: UNIX command overview
406 :    
407 :     Disk usage.
408 :     -----------
409 :    
410 :     `du'
411 :     Show number of blocks used by a file or files.
412 :    
413 :     `df'
414 :     Show the state of usage for one or more disk partitions.
415 :    
416 :     
417 :     File: unix.info, Node: Other users, Next: Contacting users, Prev: Disk usage, Up: UNIX command overview
418 :    
419 :     Show other users logged on
420 :     --------------------------
421 :    
422 :     `users'
423 :     Simple list of other users.
424 :    
425 :     `finger'
426 :     Show who is logged onto this and other systems.
427 :    
428 :     `who'
429 :     List of users logged into this system.
430 :    
431 :     `w'
432 :     Long list of who is logged onto this system and what they are
433 :     doing.
434 :    
435 :     
436 :     File: unix.info, Node: Contacting users, Next: Mail, Prev: Other users, Up: UNIX command overview
437 :    
438 :     Contacting other users
439 :     ----------------------
440 :    
441 :     `write'
442 :     Send a simple message to the named user, end with <CTRL-D>. The
443 :     command `mesg n' switches off messages receipt.
444 :    
445 :     `talk'
446 :     Interactive two-way conversation with named user.
447 :    
448 :     `irc'
449 :     Internet relay chat. A conferencing system for realtime multi-user
450 :     conversations, for addicts and losers.
451 :    
452 :     
453 :     File: unix.info, Node: Mail, Next: File transfer, Prev: Contacting users, Up: UNIX command overview
454 :    
455 :     Mail senders/readers
456 :     --------------------
457 :    
458 :     `mail'
459 :     The standard (old) mail interface.
460 :    
461 :     `Mail'
462 :     Another mail interface.
463 :    
464 :     `elm'
465 :     Electronic Mail program. Lots of functionality but poor support
466 :     for multimedia.
467 :    
468 :     `pine'
469 :     Rumours (untrue) are that pine stands for Pine is Not Elm; it
470 :     actually stands for nothing at all. Improved support for
471 :     multimedia but very slow and rather stupid at times. Some of the
472 :     best features of elm have been removed!
473 :    
474 :     `mailtool'
475 :     Sun's openwindows client program.
476 :    
477 :     `rmail'
478 :     A mail interface built into the emacs editor.
479 :    
480 :     `netscape mail'
481 :     A mail interface built into the netscape navigator.
482 :    
483 :     `zmail'
484 :     A commerical mail package.
485 :    
486 :     `tkrat'
487 :     A graphical mail reader which supports most MIME types, written in
488 :     tcl/tk. This program has a nice feel and allows you to create a
489 :     searchable database of old mail messages, but has a hopeless
490 :     locking mechanism.
491 :    
492 :     
493 :     File: unix.info, Node: File transfer, Next: Compilers, Prev: Mail, Up: UNIX command overview
494 :    
495 :     File transfer
496 :     -------------
497 :    
498 :     `ftp'
499 :     The File Transfer program - copies files to/from a remote host.
500 :    
501 :     `ncftp'
502 :     An enhanced ftp for anonymous login.
503 :    
504 :     
505 :     File: unix.info, Node: Compilers, Next: Interpreted languages, Prev: File transfer, Up: UNIX command overview
506 :    
507 :     Compilers
508 :     ---------
509 :    
510 :     `cc'
511 :     The C compiler.
512 :    
513 :     `CC'
514 :     The C++ compiler.
515 :    
516 :     `gcc'
517 :     The GNU C compiler.
518 :    
519 :     `g++'
520 :     The GNU C++ compiler.
521 :    
522 :     `ld'
523 :     The system linker/loader.
524 :    
525 :     `ar'
526 :     Archive library builder.
527 :    
528 :     `dbx'
529 :     A symbolic debugger.
530 :    
531 :     `gdb'
532 :     The GNU symbolic debugger.
533 :    
534 :     `xxgdb'
535 :     The GNU debugger with a windown driven front-end.
536 :    
537 :     `ddd'
538 :     A motif based front-end to the gdb debugger.
539 :    
540 :     
541 :     File: unix.info, Node: Interpreted languages, Next: System statistics, Prev: Compilers, Up: UNIX command overview
542 :    
543 :     Other interpreted languages
544 :     ---------------------------
545 :    
546 :     `perl'
547 :     Practical extraction an report language.
548 :    
549 :     `tcl'
550 :     A perl-like language with special support for building user
551 :     interfaces and command shells.
552 :    
553 :     `scheme'
554 :     A lisp-like extensible scripting language from GNU.
555 :    
556 :     `mercury'
557 :     A prolog-like language for artificial intelligence.
558 :    
559 :     
560 :     File: unix.info, Node: System statistics, Next: System identity, Prev: Interpreted languages, Up: UNIX command overview
561 :    
562 :     Processes and system statistics
563 :     -------------------------------
564 :    
565 :     `ps'
566 :     List system process table.
567 :    
568 :     `vmstat'
569 :     List kernel virtual-memory statistics.
570 :    
571 :     `netstat'
572 :     List network connections and statistics.
573 :    
574 :     `rpcinfo'
575 :     Show rpc information.
576 :    
577 :     `showmount'
578 :     Show clients mounting local filesystems.
579 :    
580 :     
581 :     File: unix.info, Node: System identity, Next: Internet resources, Prev: System statistics, Up: UNIX command overview
582 :    
583 :     System identity
584 :     ---------------
585 :    
586 :     `uname'
587 :     Display system name and operating system release.
588 :    
589 :     `hostname'
590 :     Show the name of this host.
591 :    
592 :     `domainname'
593 :     Show the name of the local NIS domain. Normally this is chosen to
594 :     be the same as the BIND/DNS domain, but it need not be.
595 :    
596 :     `nslookup'
597 :     Interrogate the DNS/BIND name service (hostname to IP address
598 :     conversion).
599 :    
600 :     
601 :     File: unix.info, Node: Internet resources, Next: Text/postscript, Prev: System identity, Up: UNIX command overview
602 :    
603 :     Internet resources
604 :     ------------------
605 :    
606 :     `archie, xarchie'
607 :     Search the internet ftp database for files.
608 :    
609 :     `xrn, fnews'
610 :     Read news (browser).
611 :    
612 :     `netscape, xmosaic'
613 :     Read world wide web (WWW) (browser).
614 :    
615 :     
616 :     File: unix.info, Node: Text/postscript, Next: Pictures/graphics, Prev: Internet resources, Up: UNIX command overview
617 :    
618 :     Text formatting and postscript
619 :     ------------------------------
620 :    
621 :     `tex, latex'
622 :     Donald Knuth's text formatting language, pronounced "tek" (the x
623 :     is really a greek "chi"). Used widely for technical publications.
624 :     Compiles to dvi (device independent) file format.
625 :    
626 :     `texinfo'
627 :     A hypertext documentation system using tex and "info" format. This
628 :     is the GNU documentation system. This UNIX guide is written in
629 :     texinfo!!!
630 :    
631 :     `xdvi'
632 :     View a tex dvi file on screen.
633 :    
634 :     `dvips'
635 :     Convert dvi format into postscript.
636 :    
637 :     `ghostview, ghostscript'
638 :     View a postscript file on screen.
639 :    
640 :     
641 :     File: unix.info, Node: Pictures/graphics, Next: Miscellaneous, Prev: Text/postscript, Up: UNIX command overview
642 :    
643 :     Picture editors and processors
644 :     ------------------------------
645 :    
646 :     `xv'
647 :     Handles, edits and processes pictures in a variety of standard
648 :     graphics formats (gif, jpg, tiff etc). Use `xv -quit' to place a
649 :     picture on your root window.
650 :    
651 :     `xpaint'
652 :     A simple paint program.
653 :    
654 :     `xfig'
655 :     A line drawing figure editor. Produces postscript, tex, and a
656 :     variety of other output formats.
657 :    
658 :     `xsetroot'
659 :     Load an X-bitmap image into the screen (root window) background.
660 :     Small images are tiled.
661 :    
662 :     
663 :     File: unix.info, Node: Miscellaneous, Prev: Pictures/graphics, Up: UNIX command overview
664 :    
665 :     Miscellaneous
666 :     -------------
667 :    
668 :     `date'
669 :     Print the date and time.
670 :    
671 :     `ispell'
672 :     Spelling checker.
673 :    
674 :     `xcalc'
675 :     A graphical calculator.
676 :    
677 :     `dc,bc'
678 :     Text-based calculators.
679 :    
680 :     `xclock'
681 :     A clock!
682 :    
683 :     `ping'
684 :     Send a "sonar" ping to see if another unix host is alive.
685 :    
686 :     
687 :     File: unix.info, Node: Terminals, Next: The X window system, Prev: UNIX command overview, Up: The login environment
688 :    
689 :     Terminals
690 :     =========
691 :    
692 :     In order to communicate with a user, a shell needs to have access to
693 :     a terminal. Unix was designed to work with many different kinds of
694 :     terminals. Input/output commands in Unix read and write to a virtual
695 :     terminal. In _reality_ a terminal might be a text-based Teletype
696 :     terminal (called a _tty_ for short) or a graphics based terminal; it
697 :     might be 80-characters wide or it might be wider or narrower. Unix take
698 :     into account these possibility by defining a number of instances of
699 :     terminals in a more or less object oriented way.
700 :    
701 :     Each user's terminal has to be configured before cursor based
702 :     input/output will work correctly. Normally this is done by choosing one
703 :     of a number of standard terminal types a list which is supplied by the
704 :     system. In practice the user defines the value of the environment
705 :     variable `TERM' to an appropriate name. Typical examples are `vt100'
706 :     and `xterm'. If no standard setup is found, the terminal can always be
707 :     configured manually using UNIX's most cryptic and opaque of commands:
708 :     `stty'.
709 :    
710 :     The job of configuring terminals is much easier now that hardware is
711 :     more standard. Users' terminals are usually configured centrally by the
712 :     system administrator and it is seldom indeed that one ever has to
713 :     choose anything other than `vt100' or `xterm'.
714 :    
715 :     
716 :     File: unix.info, Node: The X window system, Next: Multiple screens, Prev: Terminals, Up: The login environment
717 :    
718 :     The X window system
719 :     ===================
720 :    
721 :     Because UNIX originated before windowing technology was available,
722 :     the user-interface was not designed with windowing in mind. The X window
723 :     system attempts to be like a virtual machine park, running a different
724 :     program in each window. Although the programs appear on one screen, they
725 :     may in fact be running on unix systems anywhere in the world, with only
726 :     the output being local to the user's display. The standard shell
727 :     interface is available by running an X client application called
728 :     `xterm' which is a graphical front-end to the standard UNIX textual
729 :     interface.
730 :    
731 :     The `xterm' program provides a virtual terminal using the X windows
732 :     graphical user interface. It works in exactly the same way as a _tty_
733 :     terminal, except that standard graphical facilities like copy and paste
734 :     are available. Moreover, the user has the convenience of being able to
735 :     run a different shell in every window. For example, using the `rlogin'
736 :     command, it is possible to work on the local system in one window, and
737 :     on another remote system in another window. The X-window environment
738 :     allows one to cut and paste between windows, regardless of which host
739 :     the shell runs on.
740 :    
741 :     * Menu:
742 :    
743 :     * Components of X::
744 :     * How to set up X windows::
745 :     * X displays and authority::
746 :    
747 :     
748 :     File: unix.info, Node: Components of X, Next: How to set up X windows, Prev: The X window system, Up: The X window system
749 :    
750 :     The components of the X-window system
751 :     -------------------------------------
752 :    
753 :     The X11 system is based on the client-server model. You might wonder
754 :     why a window system would be based on a model which was introduced for
755 :     interprocess communication, or network communication. The answer is
756 :     straightforward.
757 :    
758 :     The designers of the X window system realized that network
759 :     communication was to be the paradigm of the next generation of computer
760 :     systems. They wanted to design a system of windows which would enable
761 :     a user to sit at a terminal in Massachusetts and work on a machine in
762 :     Tokyo - and still be able to get high quality windows displayed on
763 :     their terminal. The aim of X windows from the beginning is to create a
764 :     _distributed_ window environment.
765 :    
766 :     When I log onto my friend's Hewlett Packard workstation to use the
767 :     text editor (because I don't like the one on my EUNUCHS workstation) I
768 :     want it to work correctly on my screen, with my keyboard - even though
769 :     my workstation is manufactured by a different company. I also want the
770 :     colours to be right despite the fact that the HP machine uses a
771 :     completely different video hardware to my machine. When I press the
772 :     curly brace key `{', I want to see a curly brace, and not some
773 :     hieroglyphic because the HP station uses a different keyboard.
774 :    
775 :     These are the problems which X tries to address. In a network
776 :     environment we need a _common window system_ which will work on any
777 :     kind of hardware, and hide the differences between different machines as
778 :     far as possible. But it has to be flexible enough to allow us to change
779 :     all of the things we don't like - to choose our own colours, and the
780 :     kind of window borders we want etc. Other windowing systems (like
781 :     Microsoft windows) ignore these problems and thereby lock the user to a
782 :     single vendors products and a single operating system. (That, of course,
783 :     is no accident.)
784 :    
785 :     The way X solves this problem is to use the client server model.
786 :     Each program which wants to open a window on somebody's compute screen
787 :     is a client of the _X window service_. To get something drawn on a
788 :     user's screen, the client asks a server on the host of interest to draw
789 :     windows for it. No client ever draws anything itself - it asks the
790 :     server to do it on its behalf. There are several reasons for this:
791 :    
792 :     * The clients can all talk a common `window language' or _protocol_.
793 :     We can hide the difference between different kinds of hardware by
794 :     making the _machine-specific_ part of drawing graphics entirely a
795 :     problem of implementing the server on the particular hardware.
796 :     When a new type of hardware comes along, we just need to modify
797 :     the server - none of the clients need to be modified.
798 :    
799 :     * We can contact different servers and send our output to different
800 :     hardware - thus even though a program is running on a CPU in Tokyo,
801 :     it can ask the server in Massachusetts to display its window for
802 :     it.
803 :    
804 :     * When more than one window is on a user's display, it eventually
805 :     becomes necessary to move the windows around and then figure out
806 :     which windows are on top of which other windows etc. If all of the
807 :     drawing information is kept in a server, it is straightforward to
808 :     work out this information. If every client drew where it wanted to,
809 :     it would be impossible to know which window was supposed to be on
810 :     top of another.
811 :    
812 :     In X, the window manager is a different program to the server which
813 :     does the drawing of graphics - but the client-server idea still
814 :     applies, it just has one more piece to its puzzle.
815 :    
816 :     
817 :     File: unix.info, Node: How to set up X windows, Next: X displays and authority, Prev: Components of X, Up: The X window system
818 :    
819 :     How to set up X windows
820 :     -----------------------
821 :    
822 :     The X windows system is large and complex and not particularly user
823 :     friendly. When you log in to the system, X reads two files in your home
824 :     directory which decide which applications will be started what they will
825 :     look like. The files are called
826 :    
827 :     _.Xsession_
828 :     This file is a shell script which starts up a number of
829 :     applications as background processes and exits by calling a window
830 :     manager. Here is a simple example file
831 :    
832 :     #!/bin/csh
833 :     #
834 :     # .xsession file
835 :     #
836 :     #
837 :    
838 :     setenv PATH /usr/bin:/bin:/local/gnu/bin:/usr/X11R6/bin
839 :    
840 :     #
841 :     # List applications here, with & at the end
842 :     # so they run in the background
843 :     #
844 :    
845 :     xterm -T NewTitle -sl 1000 -geometry 90x45+16+150 -sb &
846 :     xclock &
847 :     xbiff -geometry 80x80+510+0 &
848 :    
849 :     # Start a window manager. Exec replaces this script with
850 :     # the fvwm process, so that it doesn't exist as a separate
851 :     # (useless) process.
852 :    
853 :     exec /local/bin/fvwm
854 :    
855 :     _.Xdefaults_
856 :     This file specifies all of the resources which X programs use. It
857 :     can be used to change the colours used by applications, or font
858 :     types etc. The subject of X-rescources is a large one and we don't
859 :     have time for it here. Here is a simple example, which shows how
860 :     you can make your over-bright xterm and emacs windows less bright
861 :     grey shade.
862 :    
863 :     xterm*background: LightGrey
864 :     Emacs*background: grey92
865 :     Xemacs*background: grey92
866 :    
867 :     
868 :     File: unix.info, Node: X displays and authority, Prev: How to set up X windows, Up: The X window system
869 :    
870 :     X displays and authority
871 :     ------------------------
872 :    
873 :     In the terminology used by X11, every client program has to contact a
874 :     _display_ in order to open a window. A display is a virtual screen
875 :     which is created by the X server on a particular host. X can create
876 :     several separate displays on a given host, though most machines only
877 :     have one.
878 :    
879 :     When an X client program wants to open a window, it looks in the UNIX
880 :     environment variable `DISPLAY' for the IP address of a host which has
881 :     an X server it can contact. For example, if we wrote
882 :     setenv DISPLAY myhost:0
883 :     the client would try to contact the X server on `myhost' and ask for
884 :     a window on display number zero (the usual display). If we wrote
885 :     setenv DISPLAY 198.112.208.35:0
886 :    
887 :     the client would try to open display zero on the X server at the host
888 :     with the IP address `198.112.208.35'.
889 :    
890 :     Clearly there must be some kind of security mechanism to prevent just
891 :     anybody from opening windows on someone's display. X has two such
892 :     mechanisms:
893 :    
894 :     _xhost_
895 :     This mechanism is now obsolete. The `xhost' command is used to
896 :     define a list of hosts which are allowed to open windows on the
897 :     user's display. It cannot destinguish between individual users.
898 :     i.e. the command `xhost yourhost' would allow _anyone_ using
899 :     yourhost to access the local display. This mechanism is only
900 :     present for backward compatibility with early versions of X
901 :     windows. Normally one should use the command `xhost -' to exclude
902 :     all others from accessing the display.
903 :    
904 :     _Xauthority_
905 :     The Xauthority mechanism has replaced the xhost scheme. It provides
906 :     a security mechanism which can distinguish individual users, not
907 :     just hosts. In order for a user to open a window on a display,
908 :     he/she must have a ticket--called a "magic cookie". This is a
909 :     binary file called `.Xauthority' which is created in the user's
910 :     home directory when he/she first starts the X-windows system.
911 :     Anyone who does not have a recent copy of this file cannot open
912 :     windows or read the display of the user's terminal. This mechanism
913 :     is based on the idea that the user's home directory is available
914 :     via NFS on all hosts he/she will log onto, and thus the owner of
915 :     the display will always have access to the magic cookie, and will
916 :     therefore always be able to open windows on the display. Other
917 :     users must obtain a copy of the file in order to open windows
918 :     there. The command `xauth' is an interactive utility used for
919 :     controlling the contents of the `.Xauthority' file. See the
920 :     `xauth' manual page for more information.
921 :    
922 :     
923 :     File: unix.info, Node: Multiple screens, Prev: The X window system, Up: The login environment
924 :    
925 :     Multiple screens
926 :     ================
927 :    
928 :     The window paradigm has been very successful in many ways, but anyone
929 :     who has used a window system knows that the screen is simply not big
930 :     enough for all the windows one would like! Unix has several solutions to
931 :     this problem.
932 :    
933 :     One solution is to attach several physical screens to a terminal.
934 :     The X window system can support any number of physical screens of
935 :     different types. A graphical designer might want a high resolution
936 :     colour screen for drawing and a black and white screen for writing
937 :     text, for instance. The disadvantage with this method is the cost of
938 :     the hardware.
939 :    
940 :     A cheaper solution is to use a window manager such as `fwvm' which
941 :     creates a virtual screen of unlimited size on a single monitor. As the
942 :     mouse pointer reaches the edge of the true screen, the window manager
943 :     replaces the display with a new "blank screen" in which to place
944 :     windows. A miniaturized image of the windows on a control panel acts as
945 :     a map which makes it possible to find the applications on the virtual
946 :     screen.
947 :    
948 :     Yet another possibility is to create virtual displays inside a single
949 :     window. In other words, one can collapse several shell windows into a
950 :     single `xterm' window by running the program `screen'. The screen
951 :     command allows you to start several shells in a single window (using
952 :     <CTRL-a CTRL-c>) and to switch between them (by typing <CTRL-a
953 :     CTRL-n>). It is only possible to see one shell window at a time, but it
954 :     is still possible to cut and paste between windows and one has a
955 :     considerable saving of space. The `screen' command also allows you to
956 :     suspend a shell session, log out, log in again later and resume the
957 :     session precisely where you left off.
958 :    
959 :     Here is a summary of some useful screen commands:
960 :    
961 :     `screen'
962 :     Start the screen server.
963 :    
964 :     `screen -r'
965 :     Resume a previously suspended screen session if possible.
966 :    
967 :     `CTRL-a CTRL-c'
968 :     Start a new shell on top of the others (a fresh `screen') in the
969 :     current window.
970 :    
971 :     `CTRL-a CTRL-n'
972 :     Switch to the next `screen'.
973 :    
974 :     `CTRL-a CTRL-a'
975 :     Switch to the last screen used.
976 :    
977 :     `CTRL-a a'
978 :     When screen is running, `CTRL-a' is used for screen commands and
979 :     cannot therefore be used in its usual shell meaning of `jump to
980 :     start of line'. `CTRL-a a' replaces this.
981 :    
982 :     `CTRL-a CTRL-d'
983 :     Detach the screen session from the current window so that it can
984 :     be resumed later. It can be resumed with the `screen -r' command.
985 :    
986 :     `CTRL-a ?'
987 :     Help screen.
988 :    
989 :     
990 :     File: unix.info, Node: Files and access, Next: C shell, Prev: The login environment, Up: Top
991 :    
992 :     Files and access
993 :     ****************
994 :    
995 :     To prevent all users from being able to access all files on the
996 :     system, unix records information about _who_ creates files and also who
997 :     is allowed to access them later.
998 :    
999 :     Each user has a unique _username_ or _loginname_ together with a
1000 :     unique _user id_ or _uid_. The user id is a number, whereas the login
1001 :     name is a text string - otherwise the two express the same information.
1002 :     A file belongs to user A if it is _owned_ by user A. User A then
1003 :     decides whether or not other users can read, write or execute the file
1004 :     by setting the _protection bits_ or the _permission_ of the file using
1005 :     the command `chmod'.
1006 :    
1007 :     In addition to user identities, there are groups of users. The idea
1008 :     of a group is that several named users might want to be able to read
1009 :     and work on a file, without other users being able to access it. Every
1010 :     user is a member of at least one group, called the _login group_ and
1011 :     each group has both a textual name and a number (_group id_). The
1012 :     _uid_ and _gid_ of each user is recorded in the file `/etc/passwd' (See
1013 :     chapter 6). Membership of other groups is recorded in the file
1014 :     `/etc/group' or on some systems `/etc/logingroup'.
1015 :    
1016 :     * Menu:
1017 :    
1018 :     * Protection bits::
1019 :     * chmod::
1020 :     * Umask::
1021 :     * s-bit and t-bit::
1022 :    
1023 :     
1024 :     File: unix.info, Node: Protection bits, Next: chmod, Prev: Files and access, Up: Files and access
1025 :    
1026 :     Protection bits
1027 :     ===============
1028 :    
1029 :     The following output is from the command `ls -lag' executed on a
1030 :     SunOS type machine.
1031 :    
1032 :     lrwxrwxrwx 1 root wheel 7 Jun 1 1993 bin -> usr/bin
1033 :     -r--r--r-- 1 root bin 103512 Jun 1 1993 boot
1034 :     drwxr-sr-x 2 bin staff 11264 May 11 17:00 dev
1035 :     drwxr-sr-x 10 bin staff 2560 Jul 8 02:06 etc
1036 :     drwxr-sr-x 8 root wheel 512 Jun 1 1993 export
1037 :     drwx------ 2 root daemon 512 Sep 26 1993 home
1038 :     -rwxr-xr-x 1 root wheel 249079 Jun 1 1993 kadb
1039 :     lrwxrwxrwx 1 root wheel 7 Jun 1 1993 lib -> usr/lib
1040 :     drwxr-xr-x 2 root wheel 8192 Jun 1 1993 lost+found
1041 :     drwxr-sr-x 2 bin staff 512 Jul 23 1992 mnt
1042 :     dr-xr-xr-x 1 root wheel 512 May 11 17:00 net
1043 :     drwxr-sr-x 2 root wheel 512 Jun 1 1993 pcfs
1044 :     drwxr-sr-x 2 bin staff 512 Jun 1 1993 sbin
1045 :     lrwxrwxrwx 1 root wheel 13 Jun 1 1993 sys->kvm/sys
1046 :     drwxrwxrwx 6 root wheel 732 Jul 8 19:23 tmp
1047 :     drwxr-xr-x 27 root wheel 1024 Jun 14 1993 usr
1048 :     drwxr-sr-x 10 bin staff 512 Jul 23 1992 var
1049 :     -rwxr-xr-x 1 root daemon 2182656 Jun 4 1993 vmunix
1050 :     The first column is a textual representation of the protection bits
1051 :     for each file. Column two is the number of hard links to the file (See
1052 :     exercises below). The third and fourth columns are the user name and
1053 :     group name and the remainder show the file size in bytes and the
1054 :     creation date. Notice that the directories `/bin' and `/sys' are
1055 :     symbolic links to other directories.
1056 :    
1057 :     There are sixteen protection bits for a UNIX file, but only twelve
1058 :     of them can be changed by users. These twelve are split into four groups
1059 :     of three. Each three-bit number corresponds to one _octal_ number.
1060 :    
1061 :     The leading four invisible bits gives information about the type of
1062 :     file: is the file a _plain file_, a _directory_ or a _link_. In the
1063 :     output from `ls' this is represented by a single character: `-', `d' or
1064 :     `l'.
1065 :    
1066 :     The next three bits set the so-called _s-bits_ and _t-bit_ which are
1067 :     explained below.
1068 :    
1069 :     The remaining three groups of three bits set flags which indicate
1070 :     whether a file can be read `r', written to `w' or executed `x' by (i)
1071 :     the user who created them, (ii) the other users who are in the group
1072 :     the file is marked with, and (iii) any user at all.
1073 :    
1074 :     For example, the permission
1075 :    
1076 :     Type Owner Group Anyone
1077 :     d rwx r-x ---
1078 :    
1079 :     tells us that the file is a directory, which can be read and written to
1080 :     by the owner, can be read by others in its group, but not by anyone
1081 :     else.
1082 :    
1083 :     _Note about directories. It is impossible to `cd' to a directory
1084 :     unless the `x' bit is set. That is, directories must be `executable' in
1085 :     order to be accessible._
1086 :    
1087 :     Here are some examples of the relationship between binary, octal and
1088 :     the textual representation of file modes.
1089 :    
1090 :     Binary Octal Text
1091 :    
1092 :     001 1 x
1093 :     010 2 w
1094 :     100 4 r
1095 :     110 6 rw-
1096 :     101 5 r-x
1097 :     - 644 rw-r--r--
1098 :    
1099 :     It is well worth becoming familiar with the octal number representation
1100 :     of these permissions.
1101 :    
1102 :     
1103 :     File: unix.info, Node: chmod, Next: Umask, Prev: Protection bits, Up: Files and access
1104 :    
1105 :     chmod
1106 :     =====
1107 :    
1108 :     The `chmod' command changes the permission or _mode_ of a file. Only
1109 :     the owner of the file or the superuser can change the permission. Here
1110 :     are some examples of its use. Try them.
1111 :    
1112 :     # make read/write-able for everyone
1113 :     chmod a+w myfile
1114 :    
1115 :     # add the 'execute' flag for directory
1116 :     chmod u+x mydir/
1117 :    
1118 :     # open all files for everyone
1119 :     chmod 755 *
1120 :    
1121 :     # set the s-bit on my-dir's group
1122 :     chmod g+s mydir/
1123 :    
1124 :     # descend recursively into directory opening all files
1125 :     chmod -R a+r dir
1126 :    
1127 :     
1128 :     File: unix.info, Node: Umask, Next: s-bit and t-bit, Prev: chmod, Up: Files and access
1129 :    
1130 :     Umask
1131 :     =====
1132 :    
1133 :     When a new file gets created, the operating system must decide what
1134 :     default protection bits to set on that file. The variable `umask'
1135 :     decides this. `umask' is normally set by each user in his or her
1136 :     `.cshrc' file (see next chapter). For example
1137 :     umask 077 # safe
1138 :     umask 022 # liberal
1139 :    
1140 :     According the UNIX documentation, the value of `umask' is `XOR'ed
1141 :     (exclusive `OR') with a value of `666 & umask' for plain files or `777
1142 :     & umask' for directories in order to find out the standard protection.
1143 :     Actually this is not quite true: `umask' only removes bits, it never
1144 :     sets bits which were not already set in `666'. For instance
1145 :    
1146 :     umask Permission
1147 :    
1148 :     077 600 (plain)
1149 :     077 700 (dir)
1150 :     022 644 (plain)
1151 :     022 755 (dir)
1152 :     The correct rule for computing permissions is not XOR but `NOT AND'.
1153 :    
1154 :     * Menu:
1155 :    
1156 :     * Making programs executable::
1157 :     * chown and chgrp::
1158 :     * Making a group::
1159 :    
1160 :     
1161 :     File: unix.info, Node: Making programs executable, Next: chown and chgrp, Prev: Umask, Up: Umask
1162 :    
1163 :     Making programs executable
1164 :     --------------------------
1165 :    
1166 :     A unix program is normally executed by typing its pathname. If the
1167 :     `x' execute bit is not set on the file, this will generate a
1168 :     `Permission denied' error. This protects the system from interpreting
1169 :     nonsense files as programs. To make a program executable for someone,
1170 :     you must therefore ensure that they can execute the file, using a
1171 :     command like
1172 :    
1173 :     chmod u+x FILENAME
1174 :    
1175 :     This command would set execute permissions for the owner of the file;
1176 :     chmod ug+x FILENAME
1177 :    
1178 :     would set execute permissions for the owner and for any users in the
1179 :     same group as the file. Note that script programs must also be readable
1180 :     in order to be executable, since the shell has the interpret them by
1181 :     reading.
1182 :    
1183 :     
1184 :     File: unix.info, Node: chown and chgrp, Next: Making a group, Prev: Making programs executable, Up: Umask
1185 :    
1186 :     chown and chgrp
1187 :     ---------------
1188 :    
1189 :     These two commands change the ownership and the group ownership of a
1190 :     file. Only the superuser can change the ownership of a file on most
1191 :     systems. This is to prevent users from being able to defeat quota
1192 :     mechanisms. (On some systems, which do not implement quotas, ordinary
1193 :     users can give a file away to another user but not get it back again.)
1194 :     The same applies to group ownership.
1195 :    
1196 :     
1197 :     File: unix.info, Node: Making a group, Prev: chown and chgrp, Up: Umask
1198 :    
1199 :     Making a group
1200 :     --------------
1201 :    
1202 :     Normally users other than root cannot define their own groups. This
1203 :     is a weakness in Unix from older times which no one seems to be in a
1204 :     hurry to change. At Oslo College, Computer Science, we use a local
1205 :     solution whereby users can edit a file to create their own groups. This
1206 :     file is called `/iu/nexus/local/iu/etc/iu-group'. The format of the
1207 :     group file is:
1208 :    
1209 :     GROUP-NAME::GROUP-NUMBER:COMMA-SEPARATED-LIST-OF-USERS
1210 :    
1211 :     
1212 :     File: unix.info, Node: s-bit and t-bit, Prev: Umask, Up: Files and access
1213 :    
1214 :     s-bit and t-bit (sticky bit)
1215 :     ============================
1216 :    
1217 :     The `s' and `t' bits have special uses. They are described as
1218 :     follows.
1219 :    
1220 :     Octal Text Name
1221 :    
1222 :     4000 chmod u+s Setuid bit
1223 :     2000 chmod g+s Setgid bit
1224 :     1000 chmod +t Sticky bit
1225 :    
1226 :     The effect of these bits differs for plain files and directories and
1227 :     differ between different versions of UNIX. You should check the manual
1228 :     page `man sticky' to find out about your system! The following is
1229 :     common behaviour.
1230 :    
1231 :     For executable files, the setuid bit tells UNIX that _regardless of
1232 :     who runs the program_ it should be executed with the permissions and
1233 :     rights of owner of the file. This is often used to allow normal users
1234 :     limited access to `root' privileges. A _setuid-root_ program is
1235 :     executed as `root' for any user. The setgid bit sets the group
1236 :     execution rights of the program in a similar way.
1237 :    
1238 :     In BSD unix, if the setgid bit is set on a directory then any new
1239 :     files created in that directory assume the group ownership of the
1240 :     parent directory and not the logingroup of the user who created the
1241 :     file. This is standard policy under system 5.
1242 :    
1243 :     A directory for which the sticky bit is set restrict the deletion of
1244 :     files within it. A file or directory inside a directory with the t-bit
1245 :     set can only be deleted or renamed by its owner or the superuser. This
1246 :     is useful for directories like the mail spool area and `/tmp' which
1247 :     must be writable to everyone, but should not allow a user to delete
1248 :     another user's files.
1249 :    
1250 :     (Ultrix) If an executable file is marked with a sticky bit, it is
1251 :     held in the memory or system swap area. It does not have to be fetched
1252 :     from disk each time it is executed. This saves time for frequently used
1253 :     programs like `ls'.
1254 :    
1255 :     (Solaris 1) If a non-executable file is marked with the sticky bit,
1256 :     it will _not_ be held in the disk page cache - that is, it is never
1257 :     copied from the disk and held in RAM but is written to directly. This
1258 :     is used to prevent certain files from using up valuable memory.
1259 :    
1260 :     On some systems (e.g. ULTRIX), only the superuser can set the sticky
1261 :     bit. On others (e.g. SunOS) any user can create a sticky directory.
1262 :    
1263 :     
1264 :     File: unix.info, Node: C shell, Next: Bourne shell, Prev: Files and access, Up: Top
1265 :    
1266 :     C shell
1267 :     *******
1268 :    
1269 :     The C shell is the command interpreter which you use to run programs
1270 :     and utilities. It contains a simple programming language for writing
1271 :     tailor-made commands, and allows you to join together unix commands
1272 :     with pipes. It is a configurable environment, and once you know it well,
1273 :     it is the most efficient way of working with unix.
1274 :    
1275 :     * Menu:
1276 :    
1277 :     * .cshrc and .login::
1278 :     * Defining variables with set and setenv::
1279 :     * Arrays::
1280 :     * Pipes and redirection::
1281 :     * tee and script::
1282 :     * Command history::
1283 :     * Command/filename completion::
1284 :     * Single and double quotes::
1285 :     * Job control::
1286 :     * Scripts with argumemts::
1287 :     * subshells::
1288 :     * Tests and conditions::
1289 :     * Loops in csh::
1290 :     * Input from the user::
1291 :     * Extracting parts of a pathname::
1292 :     * Arithmetic::
1293 :     * Examples::
1294 :    
1295 :     
1296 :     File: unix.info, Node: .cshrc and .login, Next: Defining variables with set and setenv, Prev: C shell, Up: C shell
1297 :    
1298 :     .cshrc and .login files
1299 :     =======================
1300 :    
1301 :     Most users run the C-shell `/bin/csh' as their login environment, or
1302 :     these days, preferably the `tcsh' which is an improved version of csh.
1303 :     When a user logs in to a UNIX system the C-shell starts by reading some
1304 :     files which configure the environment by defining variables like `path'.
1305 :    
1306 :     * The file `.cshrc' is searched for in your home directory. i.e.
1307 :     `~/.cshrc'. If it is found, its contents are interpreted by the
1308 :     C-shell as C-shell instructions, before giving you the command
1309 :     prompt(1).
1310 :    
1311 :     * If and only if this is the _login shell_ (not a sub-shell that you
1312 :     have started after login) then the file `~/.login' is searched for
1313 :     and executed.
1314 :    
1315 :     With the advent of the X11 windowing system, this has changed slightly.
1316 :     Since the window system takes over the entire login procedure, users
1317 :     never get to run `login shells', since the login shell is used up by
1318 :     the X11 system. On an X-terminal or host running X the `.login' file
1319 :     normally has no effect.
1320 :    
1321 :     With some thought, the `.login' file can be eliminated entirely, and
1322 :     we can put everything into the `.cshrc' file. Here is a very simple
1323 :     example `.cshrc' file.
1324 :    
1325 :     #
1326 :     # .cshrc - read in by every csh that starts.
1327 :     #
1328 :    
1329 :     # Set the default file creation mask
1330 :     umask 077
1331 :    
1332 :     # Set the path
1333 :     set path=( /usr/local/bin /usr/bin/X11 /usr/ucb /bin /usr/bin . )
1334 :    
1335 :     # Exit here if the shell is not interactive
1336 :     if ( $?prompt == 0 ) exit
1337 :    
1338 :     # Set some variables
1339 :    
1340 :     set noclobber notify filec nobeep
1341 :     set history=100
1342 :     set prompt="`hostname`%"
1343 :     set prompt2 = "%m %h>" # tcsh, prompt for foreach and while
1344 :    
1345 :     setenv PRINTER myprinter
1346 :     setenv LD_LIBRARY_PATH /usr/lib:/usr/local/lib:/usr/openwin/lib
1347 :    
1348 :     # Aliases are shortcuts to unix commands
1349 :    
1350 :     alias passwd yppasswd
1351 :     alias dir 'ls -lg \!* | more'
1352 :     alias sys 'ps aux | more'
1353 :     alias h history
1354 :    
1355 :     It is possible to make a much more complicated .cshrc file than this.
1356 :     The advent of distributed computing and NFS (Network file system) means
1357 :     that you might log into many different machines running different
1358 :     versions of unix. The command path would have to be set differently for
1359 :     each type of machine.
1360 :    
1361 :     ---------- Footnotes ----------
1362 :    
1363 :     (1) Under HPUX, two other files are also read by the C-shell. These
1364 :     are called `/etc/csh.login' and `/etc/src.csh', enabling some standard
1365 :     set-up to be configured globally. GNU/Linux has a similar system. On
1366 :     solaris systems `/etc/.login' is read.
1367 :    
1368 :     
1369 :     File: unix.info, Node: Defining variables with set and setenv, Next: Arrays, Prev: .cshrc and .login, Up: C shell
1370 :    
1371 :     Defining variables with set, setenv
1372 :     ===================================
1373 :    
1374 :     We have already seen in the examples above how to define variables in
1375 :     C-shell. Let's formalize this. To define a local variable - that is,
1376 :     one which will not get passed on to programs and sub-shells running
1377 :     under the current shell, we write
1378 :    
1379 :     set local = "some string"
1380 :     set myname = "`whoami`"
1381 :    
1382 :     These variables are then referred to by using the dollar `$' symbol.
1383 :     i.e. The value of the variable `local' is `$local'.
1384 :    
1385 :     echo $local $myname
1386 :    
1387 :     Global variables, that is variables which all sub-shells inherit from
1388 :     the current shell are defined using `setenv'
1389 :    
1390 :     setenv GLOBAL "Some other string"
1391 :     setenv MYNAME "`who am i`"
1392 :    
1393 :     Their values are also referred to using the `$' symbol. Notice that
1394 :     `set' uses an `=' sign while `setenv' does not.
1395 :    
1396 :     Variables can be also created without a value. The shell uses this
1397 :     method to switch on and off certain features, using variables like
1398 :     `noclobber' and `noglob'. For instance
1399 :     nexus% set flag
1400 :     nexus% if ($?flag) echo 'Flag is set!'
1401 :     Flag is set!
1402 :     nexus% unset flag
1403 :     nexus% if ( $?flag ) echo 'Flag is set!'
1404 :     nexus%
1405 :    
1406 :     The operator `$?VARIABLE' is `true' if VARIABLE exists and `false' if
1407 :     it does not. It does not matter whether the variable holds any
1408 :     information.
1409 :    
1410 :     The commands `unset' and `unsetenv' can be used to undefine or
1411 :     delete variables when you don't want them anymore.
1412 :    
1413 :     
1414 :     File: unix.info, Node: Arrays, Next: Pipes and redirection, Prev: Defining variables with set and setenv, Up: C shell
1415 :    
1416 :     Arrays
1417 :     ======
1418 :    
1419 :     A useful facility in the C-shell is the ability to make arrays out of
1420 :     strings and other variables. The round parentheses `(..)' do this. For
1421 :     example, look at the following commands.
1422 :     nexus% set array = ( a b c d )
1423 :     nexus% echo $array[1]
1424 :     a
1425 :     nexus% echo $array[2]
1426 :     b
1427 :     nexus% echo $array[$#array]
1428 :     d
1429 :    
1430 :     nexus% set noarray = ( "a b c d" )
1431 :     nexus% echo $noarray[1]
1432 :     a b c d
1433 :     nexus% echo $noarray[$#noarray]
1434 :     a b c d
1435 :    
1436 :     The first command defines an array containing the elements `a b c d'.
1437 :     The elements of the array are referred to using square brackets `[..]'
1438 :     and the first element is `$array[1]'. The last element is `$array[4]'.
1439 :     _NOTE: this is not the same as in C or C++ where the first element of
1440 :     the array is the zeroth element!_
1441 :    
1442 :     The special operator `$#' returns the number of elements in an array.
1443 :     This gives us a simple way of finding the end of the array. For example
1444 :     nexus% echo $#path
1445 :     23
1446 :    
1447 :     nexus% echo "The last element in path is $path[$#path]"
1448 :     The last element in path is .
1449 :    
1450 :     To find the next last element we need to be able to do arithmetic. We'll
1451 :     come back to this later.
1452 :    

Administrator
ViewVC Help
Powered by ViewVC 1.0.3