CS 342 Lecture -*- Outline -*- * The C-shell (csh) command language ** user's state *** user's position in the directory structure (hier. file system) current directory, directory stack (cd command, which must be built-in to the shell) (also pushd, popd, cd directory path) (~ and ~user syntax for home directories) *** contents of directories (which contain file names) file name expansion (when want one or more files that match pattern) file name completion (when need to be sure of getting only one name) *** contents of files accessible by programs (cat, various editors) *** accessible commands (search path, directories of commands) aliases for commands (alias) *** etc. running jobs and their status (jobs, ps) command history (history) various defaults file and directory permissions (umask) priorities (nice) ** Fundamental tasks *** navigation of state (see above) *** running other programs (extension feature) **** calling programs -with arguments positional (prog arg1 arg2 ...) keyword (prog -k x arg2 ...) -in a given environment (export environment: setenv TERM vt100) (.cshrc file that runs commands for new shells) note: setenv vs. set syntax (set TERM=vt100) -with file-I/O (<, >, >>, >&, >>&, ...) -with user-supplied input (here documents: <, both stderr and stdout >&) note: not orthogonal (in Bourne shell better: >&2 for fd2 = stderr) providing terminal characteristics in some standard place (TERM environment variable) aside: what can the programming language do? (e.g., CLU) language defines operations to get arguments (but by position or keyword?) get value of variable in environment (but scope rules may vary) match physical files with logical files (but access methods may vary) hide system calls in abstract types (e.g., filename, time, etc.) (in general this doesn't work) return "successfully" or with error code (but O.S. may not have notion of success or error code) summary: nearly impossible to keep O.S. out of program must restrict it to small part of program ** Analogies to programming languages?: *** syntax (like C) comments? # comment to end of line note: irregular in that # not recognized from terminal bad if pasting from a shell file *** parameter passing positional mechanism? (call by value, with string as the value) processing done on arguments: 1. history substitution (!?x?) 2. alias substitution (on 0th argument) 3. variable substitution ($var) 4. command substitution (`foo bar`) 5. file name substitution (x?*.[a-c]) processing must be stopped if not wanted by quotation: 'single quotes make argument literal' "double quotes make arguments with blanks one argument and suppresses file name subst." note: some characters used in history context (?) as well as file name substitution *** scope rule dynamic scoping! *** data-types characters and words (strings) basic to csh numbers only recognized in certain contexts (expressions) true-false distinction same as in C (but note strange treatment of command return codes) type checking? only a bit of dynamic checking in expressions ** Principles *** abstraction supported by aliases, command files, history mechanism, but made difficult by dynamic scoping *** automation substitution mechanisms (esp. history) file name completion *** orthogonality violated by: file name substitution vs. completion file redirection for stderr (can't separate from stdout) syntax: break vs. breaksw (stupid adoption from C, doesn't even match C exactly) distinction between expressions and commands (can't execute commands in expressions) *** regularity violated by: distinction between interactive and non-interactive use (file name completion, comments) handling of status codes of programs in expressions 1 = true and 0 = false, but return status of 0 means success. *** simplicity aliasing is too baroque, only need simple renaming, rest is best handled with command files multiplicity of mechanisms for pattern matching switch statement, expressions with pattern matching. alias vs. named commands duplication of utilities available elsewhere: jobs vs. ps, nice, nohup, time *** syntactic consistency syntax is not the same as C's, and not different enough to prevent confusion parenthesis used in too many roles (as in C): delimiting expressions, subshells ** Summary lacking in programming in the large features poor scope rules, and too complex. The use of C-langauge syntax is an admirable idea (to reduce the number of languages one must use), but it unfortunately fails because the syntax is not close enough. But various user-interface featues (file name completion, history) are attractive.