36-711 Using

References: http://www.sun.rhbnc.ac.uk/unix/unix.html, http://www.ussg.iu.edu/usail/index/concepts.html, http://www.mcsr.olemiss.edu/unixhelp/

(Frankly, http://www.google.com is another good !)

8 major aspects of Unix

1. Input/Output. This is how UNIX goes about translating data between screens, keyboards, disks, tapes and so on.

2. The Interpreter is that part that of the that inter- faces with the user. It deals with keyboard input and calling programs. In UNIX it is called the .

3. Data Management is that part of the operating system that allows you to use files and directories and the tools to manipulate them.

4. Program Development Tools in UNIX include compilers, debuggers and ed- itors and source code revision systems. There are also many non-essential tools that tend to get added over the years.

5. Time Sharing - UNIX is a -sharing operating system - time is shared between the processes that can run any one time.

6. Security - all multiple user operating systems and those that connect to other computers by modems or networks need to consider security. In UNIX this has been designed into the file system. Every user has a username and a group that (s)he belongs to and the users and groups can restrict access to others.

7. Communications - UNIX uses the TCP/Internet suite of protocols, for elec- tronic mail, file transfer, logging on to other machines, etc.

8. Accounting - UNIX provides accounting facilities that are required in a multi-user environment to control resource utilization like CPU time and use of file space.

1 Features of the Kernel Creation and management of processes A filesystem Communications A means to the system

Features of Shells (Command Interpreters) Program execution Variable and filename expansion I/O hookup Environment control Interpreted (scripts)

There are several common shells: sh, csh, tcsh, . You may be able to see which one you are using by typing $version.

The csh Shell

1. Initialization: .cshrc (.login)

2. Entering commands

(a) tab cause filename completion; ctrl-d shows completion list (b) semicolon separates multiple commands () arrows, backspace, ctrl-d, ctrl-k, etc. are active (d) end with enter

3. Command interpretation

(a) line of command input is read and broken into words by looking for

¢ separating space or &, , ;, ¡ , , (, or ) (b) words are placed on the history list (c) words are parsed: i. history substitution: !!, !n, !str or !?str ii. command alias substitution (alias ’ls -al | less’)

2 iii. I/O redirection iv. variable substitution ($str), except inside single quotes

v. command substitution (backquotes)

¡ ¢ ¢ vi. filename substitution (*, ?, [...], str,str,... , , user) (d) first word, find it in hash table based on $PATH and execute it; remaining words are the command/runstring arguments; terminating ampersand (&) causes program to run in the background (e) ctrl-c cancels a foreground job, ctrl-z suspends a foreground job (f) override special characters with backslash, e.g. \& 4. Built in-commands (not run in a new process) (a) echo, history, printenv (b) alias, unalias, set, unset, setenv, unsetenv (c) jobs, fg, bg, nice, (d) , popd, pushd, rehash, source (e) if, switch, foreach, while, shift 5. Utility programs (find program file and run in a new process) (a) , apropos, man, whatis, where, which, ps, expr (b) pwd, , ls, file, cat, , less, head, tail, wc (c) , cp, mv, rm, chmod, (d) emacs (or xemacs), clean i. Searching: ctrl-s, ctrl-r, alt-% (or esc, %) ii. Files: ctrl-x then ctrl-f, ctrl-r, ctrl-s

iii. Splitting: ctrl-x then 2, 1, £ (e) find pathname -name filename [- d] - (f) [-n -v] what filename (g) sftp, mail, pine, exmh, ssh (h) sort, uniq, diff (i) gcc, f77 6. Redirection

(a) stdin, stdout, stderr

¢ ¢ ¡ ¢ (b) ¢ , , , , with &, with grep

3 Shell Scripts (batch files, basic scripting tool) Create with emacs; line 1 is “#!/bin/csh”; do “chmod u+x myname”. # is the comment character To first line, add -n to check only, -v for verbose (before substitution), -x for - bose (after substitution). Use $1, $2, etc. for runstring parameters. Use $# for number of runstring parame-

ters.

¡ Can use n for newline, t for tab, f for formfeed, for backslash if (myexpression) mycommand if (myexpression) then ... else if (myexpression2) then ... else ... endif

In more complicated cases, use switch/endsw.

Expressions can use ! for “not”, ==. !=, && for “and”, for “or”, +, -, *, /, and % for “remainder”. (Surround by spaces.) Expressions can include -e myfilename for “file exists”, -d myfilename for “file is

a directory”, etc. ¡ The expression mycommand is true if the command executes successfully. Script files often use “set” to create variables. Be sure to precede the variable name with a dollar sign when using it after it is set. Variables can have multiple elements: set junk = (fee fi fo fum) echo $junk[2] set junk = ‘wc ˜/.login‘ echo $junk if ($junk[2] > 20) echo My .login has more than 20 words. shift [myvar] drops the first element from the runstring or myvar.

4 The at sign is used to the contents of an existing c-shell variable with the results of a calculation, e.g. set one = 1 set three = 1 @ three = $three + 2 set sum @ sum = $three + $one echo $sum unset one three

Other control structures: foreach myvar (mylist) ... end while (myexpression) ... end

5