==================== The Unix/Linux Shell ==================== -IAN! idallen@idallen.ca Reference: Learning Unix, Chapter 1, p.5-16 What is a shell for? To find and run programs. ("Programs" are also called commands or utilities.) Shells also do programming kinds of things; but, that programming is usually to aid in the finding and running of programs, not to do any kind of substantial mathematical or business calculations. Part of running a program involves supplying command line arguments to that program; the shell helps with that, too. Most (but not all) commands take what as arguments? Most - but not all - Unix commands take pathnames as arguments. "Pathnames" are names that might be file names or directory names. (Unix also has names that are neither files nor directories, e.g. the /dev/null pathname is a "character special" device.) The shell has features to make matching pathnames easier. How does the shell help run commands? Command names are almost always the names of executable files. Shells look for command names in various places, using a list of directories stored in the $PATH environment variable. Shells provide aliases and variables to save typing the same things (commands or pathnames) over and over. Shells provide wildcards (glob patterns) to generate lists of pathnames as arguments for commands. Shells provide a "history" mechanism to recall and edit the last commands you enter, to save retyping them. Shells provide ways of completing command and file names, to save typing. Where are wildcard characters (glob patterns) expanded? The shell does the wildcard (glob) expansion, NOT the commands. The wildcards are expanded before the shell looks for the command! Note how different commands treat the same set of arguments differently: $ echo * - args are interpreted as a list of text words $ ls -l * - args are interpreted as a list of pathnames (files or dirs) $ cat * - args are interpreted as a list of file names to open $ mail * - args are interpreted as a list of userids to email The shell does not know anything about the type of command being used when it prepares the argument list for a command. It is quite possible to prepare a list of arguments that don't make sense for the command being run, e.g. $ sleep * - this probably generates args that make no sense Define these terms: whitespace, arguments, wildcard, prompt ------------- Nested Shells ------------- Your default login shell on Linux is the Bourne-Again shell (bash). Your default login shell on ACADUNIX is the Korn shell (ksh). You can call up other shells by name: sh, ksh, bash, csh, tcsh (Not all shells may be installed on your system.) Each new shell is another Unix process. To get a list of your current processes, use: ps To exit from a shell: exit When you exit from your first, login shell, you log out from Unix. Another way to exit a shell is to type your EOF character. (Your EOF character is usualy CONTROL-D.) Some shells can be told to ignore EOF. Remember: all Unix programs (should) have manual pages! $ man sh $ man ksh $ man bash $ man csh $ man tcsh The shells sh, ksh, and bash (the "Bourne" shells) all have a common ancestry. They are all derived from the original Bourne shell "sh", and the programming features of these shells (if statements, for loops, etc.) all look and work the same way. This is the best shell to study. The shells csh and tcsh (the "C" shells) are similar. Their syntax for programming is not the same as the Bourne shells. We do not cover the C shell syntax in this course; these shells are notoriously buggy.