Unformatted text preview:

CSCI 3294 January 25, 2006Slide 1Administrivia• Reading assignments and Homework 1 on Web; homework due next Mondayat 5pm.Slide 2Shells — Recap/Clarifications/Corrections• As noted earlier — when you’re typing in a text window, you’re likely talking toa “shell”.• Several choices; most commonly used are probably bash and tcsh. Bydefault, you get the one in your entry in the password file. (Change withchsh command on some systems.) Can start a different one by typing itsname, like any other command.• Following discussion is about bash, but other shells provide similarfunctionality.CSCI 3294 January 25, 2006Slide 3What bash Does With What You Type — In-PlaceEditing• Simple editing — left and right arrows; ctrl-a, ctrl-e, etc.• Command history — move forward/back with up and down arrows, searchwith ctrl-r.• Tab completion — for filenames, command names, etc.• Read about bash and/or readline — man and info pages for moreinfo.Slide 4What bash Does With What You Type — ProcessingCommand Line• Shell takes completed line and expands filename wildcards, references tovariables (more about both in next slides), “tokenizes” command intocommandname and parameters, splitting (by default) at whitespace.• If that’s not what you want — e.g., to include a space in a filename, inhibitexpansion of filename wildcards, etc. — use escape character (backslash) orquotes. Single quotes inhibit all of this, double quotes all but variablesubstitution.CSCI 3294 January 25, 2006Slide 5What bash Does With What You Type — ProcessingCommand Line• Shell locates command in “search path” (PATH environment variable) andforks off a new process.• Command’s return code then available via shell variable. (Why would anyonecare? Useful in writing scripts.)Slide 6What bash Does With What You Type — Miscellaneous• Notice that some keys have meanings other than what Windows users areused to — ctrl-C, ctrl-D, ctrl-Z, possibly also ctrl-S, ctrl-Q (depending onenvironment — e.g., which terminal emulator).CSCI 3294 January 25, 2006Slide 7Environment Variables• Associated with a process (e.g., a shell) there can be “environment variables”.Useful as another way (in addition to command-line arguments, input fromfile/keyboard, etc.) of giving process information.• Some variables of interest — PATH, SHELL, HOME, USER.• To display current value, printenv FOO or echo $FOO.• To set value, FOO=value (no spaces) in bash.• To make value available to other commands, export FOO.Slide 8Filename Expansion• You probably already know about using * as a wildcard for specifying one ormore files. Other options too — “filename expansion” section in full bashmanual or info pages.• echo can be used to check what a particular expression expands to.CSCI 3294 January 25, 2006Slide 9Shell Customizations• At startup, shell reads in various configuration files (see man page fordetails). At least one will be in your home directory (.bashrc for bash).• In these files, you can– Define/redefine environment variables (e.g., PATH, PS1). For bash, besure to export them. Can define new ones (I find this useful).– Define aliases/functions (more on next slide).• Caution: The default setup on our lab machines is somewhat elaborate. Goalis to have things work right on all environments — Linux (currently FC4), butalso Mac OS X. Look at ˜defaults/system/SYSTEM.bashrc fordetails.Slide 10Shell Customizations — Aliases and Functions (bash)• Aliases are simple substitution, no parameters. E.g.alias lt=’ls -ltF’alias google=’lynx http://www.google.com’• Functions can have positional parameters. E.g.,function cd-and-show() { cd $1 ; pwd ; ls; }CSCI 3294 January 25, 2006Slide 11Processes and “Job Control”• Normally, command you type is a “foreground process”. Append &, though,and you get a “background process”.• Can make a foreground process a background process, and vice versa (fgand bg commands; jobs command).• Can even run commands in “batch” mode (batch command).Slide 12I/O Redirection• In programming classes I talk about “reading from standard input” (stdin)rather than “reading from the keyboard”. Why?How about stdout, stderr?• stdin can come from keyboard, file, or inline in shell script. stdout andstderr can go to terminal or file (overwrite or append), separately ortogether. (Syntax depends in part on which shell you’re using.)• How is this useful? (e.g., in program development? testing?)• OR — remember quotation from last time?“Write programs that do one thing and do it well. Write programs to worktogether. Write programs to handle text streams, because that is a universalinterface.”CSCI 3294 January 25, 2006Slide 13Pipes• “Pipes” provide one-way communication between programs — output ofprogram A becomes input of program B.• Key component of “the Unix philosophy” — emphasis on providing a toolkit ofsmall programs, mechanisms for combining them.• “Filters” are programs designed to work this way: sort, head, wc, sed,awk, and too many others to name.Other programs that fit in well — more, less, grep.Slide 14Filters• Some commonly-used filters:head tailsort uniqgrep wccut pastetr expandawk sed• Use these in combination with, e.g., ps, ls.• More next time, and examples.CSCI 3294 January 25, 2006Slide 15Minute Essay• How is the pace of the class so far? too fast (too much new-to-you info), tooslow (too little new-to-you info), . . .


View Full Document

TRINITY CSCI 3294 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?