1 / 21

CSE 303 Concepts and Tools for Software Development

CSE 303 Concepts and Tools for Software Development. Richard C. Davis UW CSE – 9/29/2006 Lecture 2 – Linux and Shells. Homework 0 is past due!. If you missed it, let us know You’ll need one of your late-days If you had problems, let us know We assume it all worked. Last Time.

christyk
Download Presentation

CSE 303 Concepts and Tools for Software Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 303Concepts and Tools for Software Development Richard C. DavisUW CSE – 9/29/2006 Lecture 2 – Linux and Shells

  2. Homework 0 is past due! • If you missed it, let us know • You’ll need one of your late-days • If you had problems, let us know • We assume it all worked CSE 303 Lecture 2

  3. Last Time • Getting the lay of the land • Shell (bash) • Directory structure, sense of place (pwd) • Commands • Viewing/Editing text files (emacs, cat, less) • Manipulating Files/Dirs (mkdir, cp, mv, rm) • Changing permissions (chmod) • Lot of material fast • Don’t worry, we’ll cover it all in greater depth CSE 303 Lecture 2

  4. Today • Shell as an interpreter • Shell model (Files, Users, Proceses) • Shell language details • Expansions • History Access • Aliases • Command-line editing CSE 303 Lecture 2

  5. How to think about the shell • Interprets a language • Language: program names, arguments • Interpreter actions • Runs program • Passes arguments • Prints output • Waits for next command • Program Capabilities • Control filesystem • Control devices: network (mail), display (windows) • Launch other programs Like Java? CSE 303 Lecture 2

  6. Shell Programming Model • Files • Users • Processes • We’ve already looked at files CSE 303 Lecture 2

  7. Users • 1 file-system, 1 OS, 1 CPU, many users • Users have • Names (whoami, who) • Passwords (/etc/passwd) • Home directory (and quotas) • Default shell (~/.bash_profile) • Groups CSE 303 Lecture 2

  8. Permissions • Permissions • For every file and directory (ls –a) • For user (chown), group (chgrp), and others • Read, write, or execute • Change with chmod • Changing Permissions: chmod • Example: chmod –R go-rw • Superuser: root CSE 303 Lecture 2

  9. Processes • Process = running program • “Applications” can have many • Shell is a process (ends on exit) • Default: shell waits for process to finish • Great for ls • Bad for emacs (need emacs&, or ^z bg) • Commands for controlling processes • jobs, fg, bg, kill, ps top CSE 303 Lecture 2

  10. Shell model is simple, really… • Model = files, users, processes • GUIs hide this • Programmers need to get to it • Where complexity comes from • I/O Devices (network, display, keyboard, etc.) • Language • Designed for fast typing • Designed for quick and dirty scripting CSE 303 Lecture 2

  11. The shell language • Words and spaces → Call prog w/ args • Types of words (not an exhaustive list) • Built-ins (cd, type) • Program names (ls, cat) • Program arguments (-R, file.txt) • Expansions (filename wildcards, braces) • History access • Aliases • Pipes and redirections • Shell and environment variables • Programming constructs (if, loops, arrays, exprs.) CSE 303 Lecture 2

  12. Filename Wildcard Expansion • Words can expand to multiple filenames • ~uname → home directory of “uname” • ~ → current user’s home directory • * (by itself) → all files in current directory • Except those starting with “.” • * → matches 0 or more filename characters • ? → matches 1 filename character • [abc],[a-z] → any character in set, range • [!a],[^a] → any character not in set, range • This happens before passing to program CSE 303 Lecture 2

  13. Why use file wildcards? • When typing • Saves time • In scripts • Helps if you don’t know what files are present • cat * - to get all files in a directory • What if you want special characters? • Use quoting "*" • Use escaping \* CSE 303 Lecture 2

  14. Brace Expansion • Create multiple strings from single string • Not just for file names • Example • Typed: echo Garbage{In,Out} • Expanded: echo GarbageIn GarbageOut CSE 303 Lecture 2

  15. History Access • List of all commands typed • Way to see what you’ve done • Shortcut for repeating previous commands • Not so useful in scripts • Syntax • history • !c – repeat last command starting with “c” • !! – repeat last command CSE 303 Lecture 2

  16. Aliases • Shorthand for frequently typed commands • Usually put in ~/.bashrc • Different from variables (see these later) • Syntax • Define alias alias ll=“ls -l” • View alias alias ll or type ll • Remove alias unalias ll CSE 303 Lecture 2

  17. More word types • Most interesting yet to come! • Pipes and redirections • Shell and environment variables • Programming constructs • We’ll cover these in more detail later CSE 303 Lecture 2

  18. Command Line Editing • Shortcuts for navigating/editing commands • Extremely helpful when typing • Especially in terminals (e.g. when no arrow keys) • No help in scripts • Bash similar to emacs • Interesting cases • Up/Down arrows: access command history • Tab: Filename completion (space in emacs) • C-s: Stops displaying output until C-q CSE 303 Lecture 2

  19. Summary • Environment: files, users, processes • Use shell to manipulate environment • Command line • Scripts • Shell language • Commands and built-ins • Program options and arguments • Expansions, history, aliases • Command-line editing CSE 303 Lecture 2

  20. Reading • Linux Pocket Guide • Read • p1-33 (Intro, Basics) • p104-107 (Viewing Processes) • p110-114 (Users and Their Environment) • Skim p37-46, 60-63 (for commands used in lectures) • Bash Reference Manual • See “Computing Resources” on web page • Skim sections 8.4.1-8.4.4 (Command-line editing) CSE 303 Lecture 2

  21. Next Time • Combining Commands • I/O redirection • Logic expressions • Quoting and escaping • Variables • Shell scripting introduction CSE 303 Lecture 2

More Related